How to detect if I am WindowsImpersonationContext ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
We have a server process that needs at some point to revert to its own
identity to perform some privilege tasks, we do so by calling
WindowsImpersonationContext context = WindowsIndentity.Impersonate
( IntPtr.Zero );

We later call context.Undo(); to revert back to the user's identity.

While performing some taks our server would need to know if it is
performing a task in the user's context or its own context. Is there a way
to determine the context we are currently running in?

Thank you!
 
Hi

Based on my understanding, you want to know current user's identity.

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
String username = wp.Identity.Name;
WindowsPrincipal.Identity Property [C#]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemsecurityprincipalwindowsprincipalclassidentitytopic.asp

If I have any misunderstanding, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top