Created
December 5, 2012 21:27
-
-
Save codingoutloud/4219680 to your computer and use it in GitHub Desktop.
Am I running as an Administrator?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Security.Principal; | |
// Is this thread running with Administrator role? | |
private static bool RunningAsAdministrator() | |
{ | |
var identity = WindowsIdentity.GetCurrent(); | |
if (identity == null) return false; // Administrator should always have access to this | |
var principal = new WindowsPrincipal(identity); | |
return principal.IsInRole(WindowsBuiltInRole.Administrator); | |
} |
Another admin-like power is registry access. This thread has a few interesting tidbits: http://stackoverflow.com/questions/1188723/how-do-i-check-whether-a-user-is-allowed-to-read-write-a-particular-registry-k
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also http://powershell.com/cs/blogs/tips/archive/2013/09/24/testing-administrator-privileges.aspx
Same Admin Account shows...
Running as Admin: Mandatory Label\High Mandatory Level Label S-1-16-12288
Running as Civilian: Mandatory Label\Medium Mandatory Level Label S-1-16-8192