Determine PID of process by user and name

(imported topic written by MattPeterson)

I would like to deterimne the PID of a process based on the user name and image name. It dosen’t look like there are built in inspectors for user name of a process, has anyone had any luck doing this? I need to determine the PID to terminate a process that could have several instances running under different user names.

(imported comment written by dmoore21)

If you can specify the namespace in a WMI query, then the answer is yes, you should be able to pull information relating to processes.

(imported comment written by MattPeterson)

I can’t find a way to pull that information from WMI, there is no property for user under the Win32_Process class. There is a creation method called “GetOwner” that should provide the user, but I’m not sure if I can use that in a WMI query. Can you post an example please?

http://msdn.microsoft.com/en-us/library/aa394372(v=vs.85).aspx

(imported comment written by cstoneba)

there appears to be an inspector for it in Windows, not sure if it can be used for what you want though:

q: properties whose (it as string as lowercase contains “pid”)

A: pid of : integer

A: ppid of : integer

A: engine pid of : integer

T: 1.978 ms

I: plural property

(imported comment written by MattPeterson)

I found the pid inspectors, but not user name inspectors for a process…

I’m looking to do something like this (I made up the user of it part)

pid of process whose (name of it = “iexplore.exe” and user of it = “user2”)