I'd like to monitor elevated processes running on a machine while a non-administrative user is logged in.
Basically, I want to run the following made-up code from C#:
var elevatedWindows = Process.GetProcesses().Where(p => p.IsElevated || p.ChildWindows.Any(cw => cw.IsElevated));
So far, the only thing I've found to give me the information I want appears to be a BUG in the .NET System.Diagnostics.Process class, as described here:
http://www.codeproject.com/Articles/302856/Bugs-in-System-Diagnostics-Process-Class
If I understand this correctly, the article says that if my program is not running with elevated permissions, it will generate a WIN32 exception with NativeErrorCode
equal to 5 if you try to get an elevated process's StartTime
or HasExited
properties.
I feel like this could be an easy workaround for my issue - try to get StartTime
or HasExited
from a non-elevated program and if it produces that error, it is an elevated process.
Problem is, I can't seem to get this to work reliably, HasExited
errors unreliably when I've manually right-clicked notepad and selected "Run as Administrator", and used GetProcessesByName("notepad")
Even more troublesome is I can't isolate individual Explorer Windows. Explorer.exe is always running, and can be elevated, but even if it is running WITHOUT elevation you can still manually start the process as elevated a number of different ways, none of which effect the parent explorer.exe process.
So I guess I need to find WindowHandles from the spawned processes, or their child threads, and somehow see if the window is elevated?
Any help would be appreciated.