Detect if running as Administrator with or without elevated privileges?
I have an application that needs to detect whether or not it is running with elevated privileges or not. I currently have code set up like this: static bool IsAdministrator() { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole (WindowsBuiltInRole.Administrator); } This works to detect if a user is an administrator or not, but doesn't work if running as an administrator without elevation. (For example in vshost.exe). How can I determine whether or not elevation is [already in force or] possible ?