Batch file to kill and restart not responding program - file

I am running a program (Win7) which sometimes gets stuck and not responding.
Just wanted your help to write batch process that can check the program status and if it's Not responding then close and open it again

Test this: it should only relaunch be2beat when the task is not responding, and has been killed forcefully.
#echo off
taskkill /im "Be2Beat.exe" /fi "STATUS eq NOT RESPONDING" /f >nul && start "" "C:\Program Files (x86)\Be2Beat\Be2Beat Multimedia Platform\Be2Beat.exe"

This will run it on a continuous loop to monitor.
Create file 2.bat
#echo off
:loop
taskkill /im "Be2Beat.exe" /fi "STATUS eq NOT RESPONDING" /f >nul && start "" "C:\Program Files (x86)\Be2Beat\Be2Beat Multimedia Platform\Be2Beat.exe"
goto loop

Related

Turning Off a Program When the other one closes .Bat file

This is my code so far ive tested it and both programs open when .bat is run , What im after is the code to close program 2 when program 1 closes any help would be appriciated as i have no coding knowledge :(
#echo off
start "TestFolder" "C:\Program Files (x86)\testfolder\test1.exe" %1
start "Testfolder2" "C:\Program Files (x86)\testfolder2\test2.exe"
taskkill /f /im test2.exe
exit
You need to setup a FOR /F Loop to monitor the output of TaskList to check for the window title of the 2nd program (and you'll need to explicitly set the window title of that program to something unique to do that.)
Then you will need to use Taskkill to kill the other task.
#(SETLOCAL
echo off )
CALL :Main
( ENDLOCAL
EXIT /B )
:Main
start "TestFolder1" "C:\Program Files (x86)\testfolder\test1.exe" %1
start "Testfolder2" "C:\Program Files (x86)\testfolder2\test2.exe"
CALL :Loop
taskkill /f /im test2.exe
GOTO :EOF
:loop
SET /A "n=10"
TIMEOUT 10
tasklist /V /NH /FI "IMAGENAME eq test1.exe" | FIND /I "TestFolder1" &&(
GOTO :loop
)
GOTO :EOF

Taskkill and timer in batch

I currently have this batch script:
start udp%1.exe
timeout /t %2
taskkill /f /im "udp%1.exe"
This works great and kills the program after a selected amount of time, however if I was to manually close udp%1.exe and start another one with the same ID the timer from the other batch script is still running and will kill the next launched. I'm not entirely sure if I can check if the process is still running in batch? and if so to close the timer so it doesn't kill others with the same ID?
Try this code:
#echo off
start "udp%1.exe"
timeout /t %2
tasklist /FI "IMAGENAME eq udp%1.exe" 2>NUL | find /I /N "udp%1.exe">NUL
if "%ERRORLEVEL%"=="0" goto yes
goto no
:yes
taskkill /f /im "udp%1.exe"
exit
:no
exit
It waits the selected amount of time and if the program is running, it closes it, and if the program is not running, it exits. If you wan't to detect if the program is closed while the timer is still running, you might want to look into vbs scripts. :)

Make a .batch file to start/stop a program?

I need a batch (.bat) file that opens a program if it's not open, and stops the program if it is open. I have a game where when the launcher is closed, it stays open in the background. And I have to end it with task manager or else I can't launch it because steam doesn't like it when an app is open two times (it doesn't allow it), so I would like a batch file that does this for me, then bind it to a macro.
To check if your programm is running : (Here an example with notepad.exe)
#echo off
Set "MyProcess=Notepad.exe"
tasklist | find /i "%MyProcess%">nul && echo %MyProcess% Is running || echo %MyProcess% Is not running
So you can do like that :
#echo off
Set "MyProcess=Notepad.exe"
tasklist | find /i "%MyProcess%">nul && Taskkill /F/IM "%MyProcess%" || start "%MyProcess%"
This is another way to do it:
#echo off
tasklist /fi "imagename eq Launcher.exe" |find "." > nul && taskkill /f /im "Launcher.exe" & goto :EOF
tasklist /fi "imagename eq Launcher.exe" |find "." > nul || start "" steam://rungameid/243870 & goto :EOF
So I figured this out:
#echo off
tasklist /fi "imagename eq Launcher.exe" |find ":" > nul
if errorlevel 0 taskkill /f /im "Launcher.exe" && exit
start steam://rungameid/243870
exit
The logic behind it is that if you can kill the process, then end the prompt before you can create a new session of the process. But if the process can't be killed, then make a new session of it, then end the prompt.

I want to run and kill a process with same batch file

I have bitlord I want this program to run when i click a batch file and when i don't want this program to run i want to kill it with same batch file. Can anyone please write the script Thanks a lot for giving your time.
I tried it scripting but failed.
If bitlord is not running then this will launch it
If bitlord is running then this will kill it
Change line 2 and line 3 to set the program name and path.
#echo off
set "program=bitlord.exe"
set "folder=c:\program files\bitlord"
tasklist |find /i "%program%" >nul || start "" "%folder%\%program%" & goto :EOF
tasklist |find /i "%program%" >nul && taskkill /f /im "%program%" & goto :EOF
Okay. I think i understand your question now:
#echo off
taskkill.exe /f /im notepad.exe
start calc.exe
The magic is to use the start command which starts a new command asynchronous. Meaning, it doesn't wait for the termination.

Batch file, run next program if already running

Basically I have a simple batch script just now that starts a program multiple times let's call it 1.exe, 1.exe will launch 20 times and then be killed after % amount of seconds (specified by a command line argument).
What I need done is if 1.exe is already running, launch 2.exe instead, if 2.exe and 1.exe are already running launch 3.exe instead and so on.
All the code I really have just now is
Timeout /t 20 /nobreak >nul
echo.
taskkill /F /IM %programname%
echo.
pause >nul
and also the launching of the 1.exe
Any help is appreciated.
The Batch code below launch 2.exe if 1.exe is already running, launch 3.exe if 2.exe is already running and so on:
for /L %%i in (1,1,20) do (
for /F "skip=3" %%e in ('tasklist /fi "imagename eq %%i.exe"') do (
if "%%e" equ "%%i.exe" set lastExe=%%i
)
)
set /A lastExe+=1
%lastExe%.exe

Resources