Adel Boutros
Adel Boutros

Reputation: 10295

Batch script to close all open Command Prompt windows

I have a .cmd file which I call to open multiple instances of Command Prompt via:

launcher.cmd -fs
launcher.cmd -tds
launcher.cmd -fsd

Each command open a new command prompt.

So what I want to do is create a batch file to automatically close all the opened Command Prompt instead of manually doing it.

Upvotes: 13

Views: 47194

Answers (3)

sarh
sarh

Reputation: 6637

Just a little note why accepted answer from Rene may not work. I was starting my apps from cmd file like

start "" my.exe -my -args

where my.exe was a console app and it was looking like cmd window I wanted to kill, but process name was not cmd.exe (!) and I had to use command like

taskkill /IM my.exe

So in some cases it worth to check the real process name, for example in the windows task manager.

Upvotes: 1

rene
rene

Reputation: 42494

Be carefull: you might kill more processes than you want:

taskkill /IM cmd.exe

You can add extra filters:

taskkill /IM cmd.exe /FI "WINDOWTITLE eq launcher*"

use

tasklist /FI "imagename eq cmd.exe " /V

to get a glimpse of what cmd.exe processes will be taskkill-ed

You could add the /F parameter to force the process to close but I would only use that if the process doesn't respond to a normal request.

Upvotes: 26

ant
ant

Reputation: 54

TASKKILL /F /IM cmd.exe /T 

good solution

Upvotes: -2

Related Questions