Windows – Kill process by name and owner

killprocesswindowswindows 7

Before I look into reinventing the wheel and roll my own, is anyone aware of an application/utility that allows me to kill processes, filtering by both process name and process owner? Alternatively could this be done through powershell? (My powershell-fu is sadly lacking).

I've looked at both pskill and taskkill. Although pskill allows terminating by process name, it doesn't allow me to further filter by process owner. I've also looked at WMI via wmic (wmic process), but the WMI interface doesn't return the process owner (at least from what I can tell), so can't use this either.

I do a chunk of development on Windows. Some of this involves dealing with Component Services (COM+). COM+ has a generic host process – dllhost.exe – that's used both for custom (i.e., stuff I've developed) elements and system processes. I can differentiate them by the owner they run as. So, for example, I want to kill all the dllhost.exe processes owned by me, but ignore the ones owned by SYSTEM.

This would save me going in to Task Manager on a regular basis and identifying and manually killing each one 🙂

Best Answer

In powershell you would do:

gwmi -query "select * from win32_process where name='PROCESSNAME.exe'" | %{if($_.GetOwner().User -eq 'USERNAME'){$_.terminate()}}