Skip to content

Instantly share code, notes, and snippets.

@codingoutloud
Created December 5, 2012 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingoutloud/4219680 to your computer and use it in GitHub Desktop.
Save codingoutloud/4219680 to your computer and use it in GitHub Desktop.
Am I running as an Administrator?
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);
}
@codingoutloud
Copy link
Author

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

@codingoutloud
Copy link
Author

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