1

I'm trying to determine if another application is running as an administrator. There are 100's of SO questions about finding if your application is or not, but not for another application.

If I do var processes = Process.GetProcesses(); and loop through them, they don't appear to have any "Elevated" or "IsAdministrator" properties on them. I also found a function on here to get the Owner but they all come back as "My-Laptop\Me" so that's not working for me the way I hoped it would.

Is there a way to find this? I'm on Win 8.1 and would prefer something that works for 7 as well, but if it only works for 8.1+ that's totally fine.

Thanks!

EDIT: My application has to run as an administrator.

Timothy
  • 1,198
  • 3
  • 10
  • 30
  • UAC is a solution to *shatter attacks*, a nasty security problem originally present in Windows that worked by an unprivileged process hijacking the elevated rights of another process to do damage. Lots and lots of ways to do that, could be as simple as sending keystrokes. Stupid Microsofties, of course they should make it *easy* to find such a process! Still doesn't work, UAC isn't that dumb. So what would be the point of adding the feature? There is nothing useful you can do with it. – Hans Passant Jul 27 '15 at 21:52

2 Answers2

1

Assuming your process is not running as administrator, trying to get information about a process that is elevated via UAC (such as its MainWindowTitle) will throw an AccessDenied exception, where a non-elevated process will permit you access to that information. This assumes you also verify the owner of the process to check that it's you.

try
{
    var foo = process.MainWindowTitle;
    return false; //Process is not elevated
}
catch (Win32Exception ex)
{
    return true; //Process is elevated if ex error code is AccessDenied
}
Irshad
  • 3,071
  • 5
  • 30
  • 51
PhonicUK
  • 13,486
  • 4
  • 43
  • 62
1

You can use the technique from this answer, just replace Process.GetCurrentProcess().Handle with the Process.Handle of the other process.

If you look at the code (there's quite a bit of code there) it get the process "user token" (the permissions the process is running under) and checks if this token has the administrator role or not,

Community
  • 1
  • 1
Nir
  • 29,306
  • 10
  • 67
  • 103