The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.
BOOL GetUserName(
LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);
If the function succeeds, the return value is nonzero, and the variable pointed to by nSize contains the number of characters copied to the buffer specified by lpBuffer, including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the current thread is impersonating another client, the GetUserName function returns the user name of the client that the thread is impersonating.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
System Information Overview, System Information Functions, LookupAccountName