Page 1 of 1

taskkill more than one program uses the same name

Posted: 21 Jul 2011 07:55
by jrtime
I am working on a batch file that contains a line similar to:

TASKKILL /F /T /IM program.exe

This works fine and kills the program.exe that I want it to kill, but it also kills other processes running using that same name.

C:\Program Files\Program1\program.exe
C:\Program Files\Common Files\program.exe

I only wanted "C:\Program Files\Program1\program.exe" to be killed, so I tried to add that whole path to the command:

TASKKILL /F /T /IM "C:\Program Files\Program1\program.exe"

but that did not work.

Finally, I tried:

TASKKILL /F /T /IM program.exe
@start "" "C:\Program Files\Common Files\program.exe"

but I was curious if there was a better way to do this that will stop the program that I want to stop, but not stop the other program that I want to stay running, even though the names are the same. Thanks.

Re: taskkill more than one program uses the same name

Posted: 21 Jul 2011 08:10
by Ed Dyreen
'
Hi jrtime

You can use the ProcessID to kill more specific. But it does require you to figure out the PID of the process you want to kill.
The best way is to save the PID when the process is launched. But this may not be possible if you didn't launch it obviously.

However there is a program called CMDOW which can enumerate this. ( and get the PID upon launch )
But not even necessary i've just checked tasklist can do it aswell.

Code: Select all

"C:\Program Files\Common Files\program.exe"
This is one way to find the PID, but you must be sure there will be only one instance launched from here, otherwise you will still need to enumerate !

I see you are new, welcome to DosTips " :mrgreen: "

Re: taskkill more than one program uses the same name

Posted: 24 Jul 2011 13:35
by orange_batch
Add a clause to this WMI VBScript of mine:

tasklist.vbs

Code: Select all

if wscript.arguments.count=2 then a=wscript.arguments(1) else a=0
set b=getobject("winmgmts:")
set c=b.execquery("select name,workingsetsize,commandline from win32_process")
for each d in c
if d.name<>"System Idle Process" and d.name<>"System" and d.name<>"svchost.exe" and d.name<>"explorer.exe" then
e=round(d.workingsetsize/1000000)
if not isnull(d.commandline) then f=replace(d.commandline,"""","") else f=null
if e>cint(a) then g=g&d.name&"*"&e&"*"&f&vblf
end if
next
wscript.echo g

The third *-delimited parameter is the process's command line. Combine this with my task killer.

viewtopic.php?f=3&t=1809&p=8712&hilit=kill#p8712

If you can anyway, that's all I'll provide.