Skip to content

Instantly share code, notes, and snippets.

@vurdalakov
Created October 28, 2020 11:12
Show Gist options
  • Save vurdalakov/06132e5ae26e40d2c9dfb7703998a1bd to your computer and use it in GitHub Desktop.
Save vurdalakov/06132e5ae26e40d2c9dfb7703998a1bd to your computer and use it in GitHub Desktop.
C#: Does current user have local admin rights
namespace Vurdalakov
{
using System;
using System.Security.Principal;
public static class CurrentUser
{
public static Boolean IsAdministrator()
{
using (var windowsIdentity = WindowsIdentity.GetCurrent())
{
var windowsPrincipal = new WindowsPrincipal(windowsIdentity);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment