How to Look Up a User's Full Name

Computers running Windows can be organized into a domain, which is a collection of computers on a Windows NT Server 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 on Windows NT:

  • Convert the user name and domain name to Unicode, if they are not already Unicode strings.

  • Look up the computer name of the domain controller (DC) by calling NetGetDCName.

  • Look up the user name on the DC computer by calling NetUserGetInfo.

  • Convert the full user name to ANSI, unless the program is expecting to work with Unicode strings.

The following sample code is a function 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[256]; // 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) );

MultiByteTOWideChar( CP_ACP, 0, Domain,

strlen(Domain)+1, wszDomain, sizeof(wszDomain) );

// 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);

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database