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.
taskkill more than one program uses the same name
Moderator: DosItHelp
Re: taskkill more than one program uses the same name
'
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.
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 " "
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"
I see you are new, welcome to DosTips " "
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: taskkill more than one program uses the same name
Add a clause to this WMI VBScript of mine:
tasklist.vbs
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.
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.