I’m writing a program that checks processes (when they start), and kills any processes that aren’t acceptable.
My program is mostly done, but I only just ran into a problem: when I try to get the path (one of the criteria) of a process running under a different user, (MainModule.FileName) I get an exception:
System.ComponentModel.Win32Exception occurred
ErrorCode=-2147467259
Message="Access is denied"
NativeErrorCode=5
Source="System"
StackTrace:
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited) at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly) at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId) at System.Diagnostics.Process.get_MainModule() at Forcep.Logic.ProcessStarted(Object sender, EventArrivedEventArgs e) in J:\Variable\Programming\Forcep\Forcep\Logic.vb:line 126
Now, the program doing the checking is running with complete administrator privileges, so I can pretty much wrangle any permission I need.
How can I obtain the path of the process? (I can use WMI, by the way, I’ve already used it for another part of this).
The solution is to have a client app running under the user in question, and using that client app to query the path etc.