batch-filecmd

How to kill 5 processes at the same time - BATCH


Is there a way to kill several processes faster?

TASKKILL /F /IM process1.exe
TASKKILL /F /IM process2.exe
TASKKILL /F /IM process3.exe
TASKKILL /F /IM process4.exe
TASKKILL /F /IM process5.exe

Instead of waiting for the previous process to finish, finish them at the same time, or is it not possible in this way? I tried using a single line with "&" but it is the same, sequential.


Solution

  • You should be able to do that using just one single instance of taskkill.exe:

    %SystemRoot%\System32\taskkill.exe /Im "Process*.exe" /F
    

    Or, as I'm certain you've not been truthful about the names of your processes:

    %SystemRoot%\System32\taskkill.exe /Fi "ImageName Eq Process1.exe" /Fi "ImageName Eq Process2.exe" /Fi "ImageName Eq Process3.exe" /Fi "ImageName Eq Process4.exe" /Fi "ImageName Eq Process5.exe" /F
    

    Even if you were satisfied with multiple taskkill.exe instances you could still use a loop, instead of writing out five individual command lines.

    Directly in :

    For %G In ("Process1.exe" "Process2.exe" "Process3.exe" "Process4.exe" "Process5.exe") Do @Start "Kill %~nG" %SystemRoot%\System32\taskkill.exe /Im "%~G" /F
    

    In a :

    @For %%G In ("Process1.exe" "Process2.exe" "Process3.exe" "Process4.exe" "Process5.exe") Do @Start "Kill %%~nG" %SystemRoot%\System32\taskkill.exe /Im "%%~G" /F