Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4463632
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-04-13 13:11:00

The following sample code is a function (GetFullName) that takes a user name and a domain name in the first two arguments and returns the user's full name in the third argument.

#include <windows.h>
#include <lm.h>
#include <stdio.h>
BOOL GetFullName( char *UserName, char *Domain, char *dest )
{
    WCHAR wszUserName[UNLEN+1]; // Unicode user name

    WCHAR wszDomain[256];
    LPBYTE ComputerName;
    struct _SERVER_INFO_100 *si100; // Server structure

    struct _USER_INFO_2 *ui; // User structure

// Convert ANSI user name and domain to Unicode

    MultiByteToWideChar( CP_ACP, 0, UserName,
        strlen(UserName)+1, wszUserName,
     sizeof(wszUserName)/sizeof(wszUserName[0]) );
    MultiByteToWideChar( CP_ACP, 0, Domain,
        strlen(Domain)+1, wszDomain, sizeof(wszDomain)/sizeof(wszDomain[0]) );
// Get the computer name of a DC for the domain.

    NetGetDCName( NULL, wszDomain, &ComputerName );
// Look up the user on the DC.

    if( NetUserGetInfo( (LPWSTR) ComputerName,
        (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui ) )
    {
        printf( "Error getting user information.\n" );
        return( FALSE );
    }
// Convert the Unicode full name to ANSI.

    WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name, -1,
        dest, 256, NULL, NULL );
    return (TRUE);
}

阅读(1872) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~