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