Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

taskkill window spaces in its title name

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:

taskkill /fi "WINDOWTITLE eq Administrator: My Window Title" 
like image 572
DarVar Avatar asked Jun 08 '12 11:06

DarVar


People also ask

What does im mean in Taskkill?

For starters, you can kill a program by using the following command: taskkill /F /IM winword.exe. Note that you have to use . EXE when using the TASKKILL command. /F means to forcefully terminate the process forcefully. /IM means the image name, i.e. the process name.

What does Taskkill do in CMD?

The taskkill command allows a user running any version of Microsoft Windows from XP on to "kill" a task from a Windows command line by PID (process id) or image name. This command is similar to end tasking a program in Windows.


1 Answers

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 
like image 58
c24w Avatar answered Sep 18 '22 12:09

c24w