GetUserName The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system. Windows 2000 and later: Use the GetUserNameEx function to retrieve the user name in a specified format. Additional information is provided by the IADsADSystemInfo interface. BOOL GetUserName( LPTSTR lpBuffer, // name buffer LPDWORD nSize // size of name buffer );
char szUser[80]; DWORD cbUser = 80; //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Get the user name of the impersonated client.
if (GetUserName (szUser, &cbUser)) { printf("The impersonated user name is %s",szUser); } else { HandleError("GetUserName failed.\n"); }
The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system. Windows 2000 and later: Use the GetUserNameEx function to retrieve the user name in a specified format. Additional information is provided by the IADsADSystemInfo interface. BOOL GetUserName(
LPTSTR lpBuffer, // name buffer
LPDWORD nSize // size of name buffer
);
unsigned long lLength=125;memset( Temp, 0, 126 );
::GetUserName( Temp, &lLength );
DWORD cbUser = 80; //--------------------------------------------------------------------
//--------------------------------------------------------------------
// Get the user name of the impersonated client.
if (GetUserName (szUser, &cbUser))
{
printf("The impersonated user name is %s",szUser);
}
else
{
HandleError("GetUserName failed.\n");
}