c# - Get logged in user's name from process running under "run as" credentials -
one can run exe user different logged in 1 (using "run as").
for example log in "user1" windows , start executable "run as" using credentials of "user2".
how retreive user name/identity of "user1" (who logged in currently) , not "user2" (which process runs under)?
i.e. system.environment.username
give user2 (as expected).
you can current identity of user under current thread running (not logged in user) using windowsidentity.getcurrent()
. alternatively can logged in user name via environment.username
property. not guaranteed user running current process however.
string username = system.security.principal.windowsidentity.getcurrent().name;
refer http://msdn.microsoft.com/en-us/library/system.environment.username.aspx
Comments
Post a Comment