Reputation: 2825
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
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