参考:C# administrator privilege - checking

    1. using System.Security.Principal;
    2. bool isElevated;
    3. using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
    4. {
    5. WindowsPrincipal principal = new WindowsPrincipal(identity);
    6. isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
    7. }
    8. // 简短版
    9. static bool IsElevated => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);