dennisV
dennisV

Reputation: 1119

Getting logged on user's name with or without domain in Windows

Is there a direct API to get the currently logged in user's name with the domain? So, it would return something like "domain\user" when a machine is on the domain, but at the same time it would return "user" when the machine is not on the domain? If there's not, what's the best way to get this information?

I noticed there's a LookupAccountName function - would that be the right direction to take?

Upvotes: 1

Views: 3596

Answers (1)

Ferruccio
Ferruccio

Reputation: 100658

Try GetUserNameEx(). It supports various name formats.

Upvotes: 3

Related Questions