Method by which C determines whether the current program is running through an administrator

  • 2020-12-09 00:59:37
  • OfStack

This article example shows how C# determines whether the current program is running through an administrator. Share to everybody for everybody reference.

The specific implementation code is as follows:


public bool IsAdministrator()
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}

Hopefully this article has helped you with your C# programming.


Related articles: