How to kill all batch files except what is currently running

How can you run a batch file that sets all the other cmd.exe that are currently running, except for the one that executes the kill command?

+4
source share
2 answers

Combining these two threads:

you can write something like this in a simple akillfile.cmd file ( akillfile.cmd )

 title=dontkillme FOR /F "tokens=2 delims= " %%A IN ('TASKLIST /FI ^"WINDOWTITLE eq dontkillme^" /NH') DO SET tid=%%A echo %tid% taskkill /F /IM cmd.exe /FI ^"PID ne %tid%^" 
+4
source

copy cmd.exe, rename it to a.exe, then use this command in the batch file: run a.exe / k taskkill / f / im cmd.exe

+1
source

All Articles