How can i checkif the user is running a n app as Admin in c#?

I have a windows app and i use the following to check if running as admin:

    public static bool IsAdministrator()
    {
        var identity = WindowsIdentity.GetCurrent();
        var principal = new WindowsPrincipal(identity);
        return principal.IsInRole(WindowsBuiltInRole.Administrator);            
    }

     if (!IsAdministrator())
     {
         AlrtBox.Show("Run as Admin");
     }

But if i set a shortcut to the .exe file and set untick the checkbox Run As Administrator, it still seems to run regardless if checked or unchecked. I guess i am checking if the user is admin on windows(which they are) , but not if the check box is checked.

I want to check if the app is run as admin , regardless of the user on windows. How can i do that ?



from Recent Questions - Stack Overflow https://ift.tt/33hU5xA
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)