taskkill more than one program uses the same name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jrtime
Posts: 1
Joined: 21 Jul 2011 07:37

taskkill more than one program uses the same name

#1 Post by jrtime » 21 Jul 2011 07:55

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.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: taskkill more than one program uses the same name

#2 Post by Ed Dyreen » 21 Jul 2011 08:10

'
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: "

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: taskkill more than one program uses the same name

#3 Post by orange_batch » 24 Jul 2011 13:35

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.

Post Reply