Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@codingoutloud codingoutloud commented Sep 24, 2013

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

This comment has been minimized.

Copy link
Owner Author

@codingoutloud codingoutloud commented Jun 6, 2014

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