char buffer[256]; // буфер
DWORD size; // размер
size = sizeof(buffer); // размер буфера
GetUserName(buffer, &size);
string userName = buffer;
BOOL WINAPI GetUserNameW(LPWSTR lpBuffer, LPDWORD lpnSize);
BOOL WINAPI GetUserNameA(LPSTR lpBuffer, LPDWORD lpnSize);
#ifdef _UNICODE
#define GetUserName GetUserNameW
#else
#define GetUserName GetUserNameA
#endif
#include <windows.h>
#include <Lmcons.h>
char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);