C++ – GetUserName() when process is run as administrator

I believe the question you want to ask Windows is “which user is logged into the current session”.

To do this, call ProcessIdToSessionId() with your own process’s ID to determine the current session ID.

Then call WTSQuerySessionInformation() with the WTSUserName option to fetch the user name.

Leave a Comment