#include
char UserName[100] = "";
DWORD *NrOfChars;
*NrOfChars = 100;
GetUserName(UserName, NrOfChars);
Good luck!
Erwin Timmerman
Here's the description from the Windows SDK:
BOOL GetUserName(
LPTSTR lpBuffer, // name buffer
LPDWORD nSize // size of name buffer
);
Parameters
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails. A buffer size of (UNLEN + 1) characters will hold the maximum length user name including the terminating null character. UNLEN is defined in Lmcons.h.
nSize
[in/out] Pointer to a DWORD variable that, on input, specifies the maximum size, in TCHARs, of the buffer specified by the lpBuffer parameter. If the function succeeds, the variable receives the number of characters copied to the buffer. If the buffer is not large enough, the function fails and the variable receives the required buffer size, in TCHARs, including the terminating null character.
Return Values
If the function succeeds, the return value is a nonzero value, 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.
Remarks
If the current thread is impersonating another client, the GetUserName function returns the user name of the client that the thread is impersonating.