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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -