Click here to Skip to main content
15,888,143 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a desktop application that is executed with Admin privileges. When this application is run by a non-admin user (by elevating the app with admin rights) say standard user, I am unable to get the standard user's (or logged on user's) environment variables, instead the application returns the Admin users environment variable. How can this issue be resolved. Please help...
Posted

1 solution

Environment variables are user specific and defined in that users profile, when you are using RunAs, Windows is loading the application in the security context and profile of that user, so you will not have access to the original logged-in user.
 
Share this answer
 
Comments
Sunil P V 10-Jun-12 0:09am    
But is there a way to hack this. I want the logged on user's environment variables even though the application is invoked as an admin user. I suppose impersonation would not work because the admin account does not fall under local system account...
Mehdi Gholam 10-Jun-12 0:50am    
The logged in user is the admin, so no.
Sunil P V 11-Jun-12 4:52am    
Mehdi, Got a hack for this: Using WMI we can get the active logged in user, even if the application is invoked (run-as) as any other user. :-)
Mehdi Gholam 11-Jun-12 5:30am    
Post an article or a tip on it :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900