How can I detect if my process is running UAC-elevated or not?

For those of us working in C#, in the Windows SDK there is a “UACDemo” application as a part of the “Cross Technology Samples”. They find if the current user is an administrator using this method:

private bool IsAdministrator
{
    get
    {
        WindowsIdentity wi = WindowsIdentity.GetCurrent();
        WindowsPrincipal wp = new WindowsPrincipal(wi);

        return wp.IsInRole(WindowsBuiltInRole.Administrator);
    }
}

(Note: I refactored the original code to be a property, rather than an “if” statement)

Leave a Comment