读取指定主域服务器上指定帐号用户的信息。其中涉及的函数参数之间需要Multibyte和Unicode之间相互转换。
MultiByteToWideChar,CP_ACP, NetGetDCName,NetUserGetInfo,
#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. " );
return( FALSE );
}
// Convert the Unicode full name to ANSI.
WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name, -1,
dest, 256, NULL, NULL );
return (TRUE);
}
#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. " );
return( FALSE );
}
// Convert the Unicode full name to ANSI.
WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name, -1,
dest, 256, NULL, NULL );
return (TRUE);
}