Windows – How to kill a process based on the partial content of its window title

batchcommand linewindows

I start a command window with a similar command:

start "DUMMYCOMMANDWINDOW"

I can then close the window using this command:

taskkill /FI "WINDOWTITLE EQ DUMMY*" /f /t

What I'd like to do, however, is to close the window based on its partial title. Something like this:

taskkill /FI "WINDOWTITLE EQ *COMMANDWINDOW" /f /t

Is there a way to do that?

Best Answer

Using PowerShell, you can do the following:

Get-Process | Where-Object { $_.MainWindowTitle -like '*commandwindow' } | Stop-Process

Get-Process returns a list of all processes, the Where-Object clause filters it based on the window title, and Stop-Process is similar to taskkill.

Related Question