In .NET/C# test if process has administrative privileges

前端 未结 10 1978
天涯浪人
天涯浪人 2020-11-27 03:35

Is there a canonical way to test to see if the process has administrative privileges on a machine?

I\'m going to be starting a long running process, and much later

10条回答
  •  孤城傲影
    2020-11-27 04:15

    Using the .NET Framework 4.5, it seems to be easier to check if a user is in the administrators group:

    WindowsPrincipal principal = WindowsPrincipal.Current;
    bool canBeAdmin = principal.Claims.Any((c) => c.Value == "S-1-5-32-544");
    

提交回复
热议问题