Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Created January 25, 2018 09:01
Show Gist options
  • Save idiotandrobot/0238019079641b0ac5f735e66edb5c8b to your computer and use it in GitHub Desktop.
Save idiotandrobot/0238019079641b0ac5f735e66edb5c8b to your computer and use it in GitHub Desktop.
Mark .NET application to run as Administrator
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
private static bool HasAdministratorPrivileges()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(id);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment