How can I tell if my process is running as Administrator?

后端 未结 5 1009

I would like to display some extra UI elements when the process is being run as Administrator as opposed to when it isn\'t, similar to how Visual Studio 2008 displays \'Admi

5条回答
  •  自闭症患者
    2020-11-29 07:52

    I think this is a good simple mechanism.

    using System.Security.Principal;
    
    WindowsIdentity identity = WindowsIdentity.GetCurrent();
    WindowsPrincipal principal = new WindowsPrincipal(identity);
    bool isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
    

提交回复
热议问题