Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Computers can be organized into a domain, which is a collection of computers network. The domain administrator maintains centralized user and group account information.
To find the full name of a user, given the user name and domain name:
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>
#pragma comment(lib, "netapi32.lib")
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,
(int) strlen(UserName)+1, wszUserName,
sizeof(wszUserName)/sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, Domain,
(int) strlen(Domain)+1, wszDomain,
sizeof(wszDomain)/sizeof(WCHAR) );
// 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 ) )
{
wprintf( L"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);
}
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!