How to isolate and kill single process between multiple similar processes
Last week we had request to create a.bat (batch) script which will do a lot of deployment stuff and one of most interesting things this script needs to done is to kill one single process.
Okay, so we try to use ms dos taskkill command, but unfortunately it was unusable in our case. We need to kill one process, but there are over 30 process running with same name etc. "testapp.exe".
Yes, every process is a windows forms instance application with different 'Windows Title'. I am not sure why but cmd taskkill by specific 'Window Title' does not worked in our case.
Things is that we have one old service like VB6 app which is running on specific server and doing some interesting business related stuff.
In task manager we have 30 process that looks like:
So, I remembered that there are one more option we can use in our case and that is WMIC.
One important thing in our case was that every running instance was started with unique run argument id '55:1:D':
So, our command to kill our process look's like:
WMIC process where "commandline like '%%testapp.exe%%55:1:D'" call terminate
With this argument '%%testapp.exe%%55:1:D' we isolate process we want to kill.
Here are some simple cases for using WMIC:
WMIC PROCESS CALL Create "calc.exe"
WMIC PROCESS WHERE Name="calc.exe" CALL Terminate
WMIC PROCESS WHERE Name="explorer.exe" call SetPriority 64
Identical to: WMIC PATH Win32_Process WHERE Name="explorer.exe" call SetPriority 64
Also check more info on this link: dedoimedo.com