taskkill window spaces in its title name

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

I've had similar problems, but found out a little bit more.

Problem

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
                                                                                               🡹
(scroll 🡺)                                                                               extra space

Solution

So to kill the process:

taskkill /F /FI "WindowTitle eq  Administrator:  CMD with custom title" /T
                                               🡹
                                             bingo
  • /F - use the force.
  • /T - kill child-processes.

If you're banging your head in a similar fashion, I recommend using tasklist to poke around inside the process properties to make sure you're getting your filters right. This ballache brought to you by Windows 8.

Note: if the title contains quotation marks, just escape the nested ones:

title "CMD with custom title"

taskkill /F /FI "WindowTitle eq  Administrator:  \"CMD with custom title\"" /T

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"