C# logged user and run as user -
i have 2 users: domain1\user1 , domain2\user2. i'm logged domain1\user1. want run app (with option 'run different user') domain2\user2. how can gets user name of person logged on windows, because environment.username return user2, want domain1\user1.
check out windowsimpersonationcontext
on msdn, believe has you're looking for.
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx
you can implement own helper class if like, declare using([establish context here])
, perform activities within code block executed user context. quite handy!
note: if decide utilize using
, sure in dispose()
method of helper release impersonation context cleans nicely when program leaves using
block.
Comments
Post a Comment