Get default user name when "Run as administrator"
-
Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks
-
Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks
You could try
GetEnvironmentStrings
. Then look forUSERNAME
variable.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
You could try
GetEnvironmentStrings
. Then look forUSERNAME
variable.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Thanks for the reply. I have already tried that. It is returning the administrators username when i run the app as "Run as administrator". But i want the system logged on user name.
-
Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks
-
Hi, Am developing a VC++ application where i need to get the username. I have tried using GetUserName() and also USERNAME. But when i run the application on Vista as "Run as administrator", this is returning the admin's username and not the username with which the system is logged in. Any suggestions on how to get the username with which the system is logged in when the application is "Run as administrator"? Thanks
Have you looked at
LsaEnumerateLogonSessions()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Thanks for the reply. I have already tried that. It is returning the administrators username when i run the app as "Run as administrator". But i want the system logged on user name.
The reason why I gave you the answer is this - I run a normal command prompt and run the set command which lists the environment variables. Here it lists
USERNAME=xxx
. I then run the command prompt as administrator and then do the same thing. TheUSERNAME
variable lists the same user.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)