Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 723
Adel Boutros Avatar asked Dec 29 '11 11:12

Adel Boutros


People also ask

How do I close a script in cmd?

If quitting CMD. EXE, sets the process exit code no. To close an interactive command prompt, the keyboard shortcut ALT + F4 is an alternative to typing EXIT.

What does @echo off mean in cmd?

echo off. When echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt again, type echo on. To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type: @echo off.


1 Answers

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.

like image 146
rene Avatar answered Oct 26 '22 14:10

rene