I\'m trying to run taskkill on a console window that has spaces in it\'s title. How can I pass this window title to taskkill. I have tried the following:
tas
I was starting cmd shell windows using AutoIt and the tip about using tasklist really helped. I already tried the double spaces but AutoIt's Run() command created the cmd.exe shell in a manner that tasklist/taskkill could not see the window title.
If I used a loop or AutoIt's WinKill()/WinClose() with the window title for the cmd prompt then AutoIt itself could close the window but my cmd prompt bat files only saw c:\windows\system32\cmd as the window title.
In this case I was able to use AutoIt to kill the window instead of from a batch script.
The trick is to name the cmd process and then kill it by calling the name you have given: The following is starting 6 parallel processes and you can kill any one of choice.
start "cmd001" cmd.exe
start "cmd002" cmd.exe
start "cmd003" cmd.exe
start "cmd004" cmd.exe
start "cmd005" cmd.exe
start "cmd 006" cmd.exe
:: kill the process you want, e.g. cmd005
taskkill /F /FI "WINDOWTITLE eq cmd005" /T
:: kill a process which has a SPACE in its name, e.g. cmd 006
taskkill /F /FI "WINDOWTITLE eq cmd 006" /T
taskkill /F /FI "WindowTitle eq Apache 8184"
Late answer (4yo), but a good way to kill a process when you know only a part of the process name is using the old WMIC.
Here's an example to find
and kill
a process named "Administrator: My Window Title"
:
WMIC PROCESS WHERE "NAME LIKE '%Administrator: My Window Title%'" CALL TERMINATE
I've had similar problems, but found out a little bit more.
I have been trying to close a CMD window (run as administrator) which has set its own window title. So, run CMD as administrator and type:
title CMD with custom title
After much faffing, the following command showed me that setting the window title puts a leading space in front of the title! (No idea why.)
c:\>tasklist /V /FI "WindowTitle eq Administrator*"
Image Name PID Session Name Session# Mem Usage Status User Name CPU Time Window Title
========== ==== ============ ======== ========= ======= =============== ======== =====================================
cmd.exe 4304 Console 1 2,492 K Running MACHINE\My Name 0:00:00 Administrator: CMD with custom title
I guess this task run on your windows server . If the title includes "Administrator : " you can not kill the task via WindowTitle equal.
You should use this : This is my killer.bat. SEARCH_PARAMETER = WHAT TITLE YOU WANNA KILL
@echo off
for /f "tokens=2 delims=," %%a in ('
tasklist /fi "imagename eq cmd.exe" /v /fo:csv /nh
^| findstr /r /c:".*SEARCH_PARAMETER[^,]*$" ') do taskkill /pid %%a