ReignBough
ReignBough

Reputation: 465

Get current username on windows

I modified my username in Control Panel -> User Accounts -> Change Your Name.

But when I use the GetUserName function, it returned my old username.

How do I get the new one?

EDIT 1

Here's the code as requested:

char user[UNLEN + 1];
DWORD user_len = UNLEN + 1;
GetUserName(user, &user_len);

Upvotes: 1

Views: 1707

Answers (1)

Felice Pollano
Felice Pollano

Reputation: 33272

Try to use the API GetUserNameEx, and passing as a format NameDisplay. I guess you changed the display name of the user, not the logon name.

Upvotes: 5

Related Questions