Created
October 28, 2020 11:12
-
-
Save vurdalakov/06132e5ae26e40d2c9dfb7703998a1bd to your computer and use it in GitHub Desktop.
C#: Does current user have local admin rights
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
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