Home > front end >  How to kill 5 processes at the same time - BATCH
How to kill 5 processes at the same time - BATCH

Time:12-01

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.

CodePudding user response:

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

CodePudding user response:

Dave. I think you can use start to run commands parallel. Something like this:

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

Here is some more information for you:

  • Using & you will run both commands no matter what happens.
  • Using && you will run the second command after the success of the first command
  • Using || you will run the second command after the first one fails to execute.
  • Related