How to write a batch file which kill multiple process - batch-file

I want a batch file that will kill all of chrome.exe process. I came across with this sample:
taskkill /im chrome.exe
which kill only the first process of chrome.exe that it find. how can I loop it?

You can use this:
taskkill /F /IM <processname.exe> /T
taskkill /F /IM Chrome.exe /T

Related

how to kill opened apps using batchfile?

I wanted to close opened app by running a batchfile code . My current code does not work and just freezes all black.
Code
#echo off
echo closing all programs...
taskkill /f /t /im explorer.exe
explorer.exe
I think taskkill /f /im explorer.exe should work oh and you should do pause or pause >nul at the end of the script else your program won't start also explorer.exe at the end of your script is not needed.

Taskkill: Do I need to specify \t parameter multiple times?

I have 2 unwanted processes running: foo.exe and bar.exe, and both have child processes started by them.
I want to use taskkill to terminate all these processes (foo.exe, bar.exe and all child ones). Do I need to use \t parameter only once or do I need to use it multiple times? I.e., which version is correct:
a) taskkill /f /im "foo.exe" /im "bar.exe" /t
b) taskkill /f /im "foo.exe" /t /im "bar.exe" /t
?
Well, a for loop will be more meaningful as you can add/remove imagenames as you please:
Using batch file:
#echo off
for %%i in (foo.exe bar.exe) do taskkill /f /im "%%i" /t
From cmdline:
for %i in (foo.exe bar.exe) do taskkill /f /im "%i" /t

Batch script kill process

I have Process1,Process2,Process3 in tasklist I want to write for loop or loop back to repeat the same task to kill the ‘n' number process
Which I mention in batch script.
Below is sample script using to kill process
#Echo Off
Tasklist | Findstr /I “Process1”
IF ERRORLEVEL 1 GOTO :Killprocess
GOTO:EOF
:Killprocess
Taskkill /IM “Process1”
If you are trying to kill the same program over and over, just do tasklist in a cmd.exe, then find its PID tag.
Example:
Image Name PID Session Name Mem Usage
========================= ======== ================ ============
firefox.exe 26356 Console 139,352 K
regedit.exe 24244 Console 9,768 K
cmd.exe 18664 Console 2,380 K
conhost.exe 2528 Console 7,852 K
notepad.exe 17364 Console 7,892 K
notepad.exe 24696 Console 22,028 K
notepad.exe 25304 Console 5,852 K
explorer.exe 2864 Console 72,232 K
After that, just put the PID into your text. I would run the program as such:
#echo off
TASKLIST
TASKKILL /PID (your PID here) /F
TASKKILL /PID (PID 2) /F
This will kill your tasks automatically. You don't need to find the tasks. If the program isn't running, then it won't kill it.
If you have a process that keeps changing its PID, or doesn't run under the same session, then run it as such:
#echo off
TASKLIST
TASKKILL /IM (program name) /F
TASKKILL /IM (program name 2) /F
Again, the program won't close if it isn't running.
Hope this helps!
Find more info here...
Thanks everyone for suggestions....done with script
#echo off
set len=3
set obj[0]=chrome.exe
set obj[1]=vlc.exe
set obj[2]=MicrosoftEdge.exe
set i=0
:loop
if %i% equ %len% goto :eof
for /f "usebackq delims== tokens=2" %%j in (`set obj[%i%]`) do (
TASKLIST |FINDSTR /I "%%j"
IF ERRORLEVEL 0 TASKKILL /IM "%%j" /F)
set /a i=%i%+1
goto loop

Script to restart a program every few minues

I've tried restarting a program every few minutes with a batch file which looks like the following. However it only opens the .exe a lot of times which causes them to crash. Anyone knows why this problem occurs?
#echo off
:loop
start "programm" "D:\Downloads\programm.exe"
timeout /t 1200 >null
taskkill /f /im "programm" >null
timeout /t 7 >null
goto loop
I hate a short answer, but it's an easy and quick fix. null is nothing, use nul as it's almost certainly skipping the invalid output name.
So the code:
#echo off
:loop
start "programm" "D:\Downloads\programm.exe"
timeout /t 1200 >nul
taskkill /f /im "programm" >nul
timeout /t 7 >nul
goto :loop
taskkill /f /im "programm" >null
Remove the >null and look why it doesn't kill the program.

Taskkill no longer works with VLC

I have a batch that used to kill VLC.
echo
rem choice /c YN /n /d Y /t 120
taskkill /im vlc.exe
Now when it runs, VLC stays open, even though the CMD reports the taskkill command was successfully sent.
Any ideas? Perhaps a VLC (currently 2.1.5) update make it no longer work.
Is taskkill /im vlc.exe /f or taskkill /im vlc.exe /t /f working for you? Had the same problem with explorer.exe a while ago...

Resources