MathuSum Mut
MathuSum Mut

Reputation: 2825

Get whether separate process is elevated

In order to get whether the current process is running with administrator privileges, we use the following C# code:

public static bool IsElevated {
    get {
        return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
    }
}

However, I am trying to find whether another separate process is elevated or not.

How do I go about doing that programmatically?

Upvotes: 1

Views: 849

Answers (1)

Dmitrii Zyrianov
Dmitrii Zyrianov

Reputation: 2318

Try this out: https://stackoverflow.com/a/4497572/3049344

var process = Process.GetProcessesByName("YouProcessName").First();
IntPtr tokenHandle;
if (!OpenProcessToken(process.Handle, TOKEN_READ, out tokenHandle))
{
         throw new ApplicationException("Could not get process token.  Win32 Error Code: " + Marshal.GetLastWin32Error());
}
                             ...

Upvotes: 2

Related Questions