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
Related
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.
I am running a command in command prompt and I want to kill it after 15 minutes. I don't care if it is completed or not. I don't want to have any human interaction to kill the running command such as someone has to press CTRL+C to kill it.
Is there a way to do it.
Please note I don;t want to use any third party tools or scripts.
start forfiles /s
timeout /t 5
Taskkill /im forfiles.exe /f
is one way.
Did you mean something like that ?
#echo off
Tracert www.google.com
timeout /t 900 /nobreak >NUL
Taskkill /im cmd.exe /f
Edit : based on the blueray's comment :
how can I put this command in a single line to use in CMD?
Tracert www.google.com & timeout /t 900 /nobreak >NUL & Taskkill /im cmd.exe /f
May be this could help
start your-command-here
ping 127.0.0.1 -n 120 > NUL
taskkill /im cmd.exe /f
Explanation:
start: this command starts executing your command
ping: it pings your local machine(ip : 127.0.0.1) for 120 sec and >NUL redirects the output to nowhere else the output of ping command will be displayed on the cmd screen
taskkill: it is used to kill any task
/im: image name of the process to be terminated. if the command is running on cmd then cmd.exe or any program that you need to kill.
Hope it helps.
Try this, works well for me:
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
#echo off
set _time=0
set _timeout=30
start myprocess.exe
:waitforprocess
set /A _time=_time+1
IF !_time! GTR !_timeout! goto TimedOut
rem TaskList will return the task list of the image as specific
rem or it will return INFO: No tasks are running.... so look for
rem the INFO statement using FindStr. FindStr will return a errorlevel
rem of 0 if it found the string and a 1 if it did not, so use that
rem to work out next steps.
rem -------------------------------------------------------------------
tasklist /NH /FI "IMAGENAME EQ myprocess.exe" | findstr INFO
rem ERRORLEVEL 1 = Did not find the string, so try again.
IF ERRORLEVEL 1 (
timeout /T 1 /NOBREAK > nul
goto :waitforprocess
)
GOTO DONE
:TimedOut
ECHO We timedout so will kill the process
taskkill /FI "IMAGENAME EQ myprocess.exe" /T /F
:Done
echo finished
I am trying to wait for the process to end, Can't use the "Start /W" because the process opens from another program.
So all in all, I need some kind of scanner to look for if the process in the WaitSession and then continue the code to the KillSession
#echo off
color 02
cd /D C:\Windows\System32
timeout -t 1
***WaitSession***
(Wait for this process to end) MightyQuest.exe
***KillSession***
taskkill /f /im PublicLauncher.exe
taskkill /f /im AwesomiumProcess.exe
Thanks
This should do it:
#echo off
color 02
cd /D C:\Windows\System32
timeout -t 1
SET TempFile="%Temp%\%RANDOM%.txt"
:WaitSession
REM Fetch the current process list. Store in a temp file for easy searching.
TASKLIST > %TempFile%
REM Reset the process "flag" variable.
SET "Process="
REM Check for a process with the target name by searching the task list for the target process name.
REM If output is returned, it will be put into the Process "flag" variable.
FOR /F "usebackq tokens=1 delims=-" %%A IN (`FINDSTR /I "MightyQuest.exe" %TempFile%`) DO SET Process=%%A
REM If nothing was returned, it means the process isn't running.
IF "%Process%"=="" GOTO KillSession
ECHO Process is still running.
REM Wait and then try again.
TIMEOUT /T 20
GOTO WaitSession
:KillSession
taskkill /f /im PublicLauncher.exe
taskkill /f /im AwesomiumProcess.exe
REM Cleanup.
DEL %TempFile% > nul
The idea here is you keep polling the active task list and when the target process is found, you delay for a few seconds and then try again.
Once it is not found in the task list, you jump to the KillSession steps.
Use wmic Windows Management Instrumentation Command
#echo off
color 02
rem why? cd /D C:\Windows\System32
timeout -t 1
:wait
TIMEOUT -t 3 /NOBREAK>nul
rem ***WaitSession***
rem (Wait for this process to end) MightyQuest.exe
for /F "tokens=*" %%G in (
'wmic process where "name='MightyQuest.exe'" get name'
) do if /i not "%%G"=="No Instance(s) Available." goto :wait
rem ***KillSession***
taskkill /f /im PublicLauncher.exe
taskkill /f /im AwesomiumProcess.exe
A vbscript
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM Win32_ProcessTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
msgbox objReceivedEvent.ProcessName
Loop
Use Win32_ProcessTraceStop to only catch terminations.
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...
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