views:

65

answers:

2

I want to get current login user name in windows xp, windows 7, in c++. How can I do this? Is there any handy API without authority problem? Many thanks!

A: 

This should work:

char sz[256];
GetEnvironmentVariable ("USERNAME", sz, 256);
Tarydon
-1: `SET USERNAME=FOO`
John Saunders
set USERNAME=AnyFakeNameIWantToMakeUp.
No Refunds No Returns
+4  A: 

Use the Win32 API GetUserName or GetUserNameEx if you want a little more options.

Brian R. Bondy