1

This can be two separate .bat files if needed, but I would prefer if it's possible on one.

I need to run a certain program, but it sometimes crashes.

I have this for a .bat so far.

It works as far as resetting the program every hour, but it does crash sometimes in between restarts.

I'd like to just have a check, so it launches if the program isn't found.

Is that possible?

@echo off
:loop
start "xx" "xxpath"
timeout /t 3600 >null
taskkill /f /im "xx" >null
timeout /t 4 >null
goto loop
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
yee man
  • 11
  • 1
  • 1
    Your question is essentially the same as this one: https://stackoverflow.com/q/415409/1531971 –  Aug 28 '18 at 17:57
  • Also, the batch file may crash at the taskkill because you didn't run the script as administrator privilege, so you didn't have the right the kill the process with higher privilege. That is one to consider. – LxL Aug 28 '18 at 18:00
  • 1
    The `NUL` device is one `L`. – Squashman Aug 28 '18 at 18:01
  • 1
    Possible duplicate of [Run batch file as a Windows service](https://stackoverflow.com/questions/415409/run-batch-file-as-a-windows-service) – Larry Shatzer Aug 28 '18 at 18:16
  • Possible duplicate of [How to check if a process is running via a batch script](https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script) – Ken White Aug 29 '18 at 01:26

1 Answers1

0

Here is a sample batch that can check if any instance of chrome.exe is running or not

If not, we start it !

@echo off
Color 0A
Set WaitTimeSeconds=20
Set App_Path=C:\Program Files\Google\Chrome\Application\chrome.exe
for %%i in (%App_Path%) do set App_Name=%%~nxi
Title Checking if any "%App_Name%" instance is running ... 
:Loop
Rem Clear the screen
cls 
Rem Kill any application that have a status equal to not responding !
Taskkill /f /fi "status eq not responding">nul 2>&1
Rem Check if any application instance is running ; if not we start it !
TASKLIST | FINDSTR %App_Name% || START "" "%App_Path%"
Timeout /t %WaitTimeSeconds% /nobreak>nul
Goto Loop
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • This seems to work fine when I put the proper path in, it does what I wanted it to do, but for some reason this also closes discord. I will relaunch discord after starting this bat but then it instantly closes again, any idea why? – yee man Aug 29 '18 at 20:59
  • Because your discord is not responding, so the script close any application that have a status not responding ! – Hackoo Aug 29 '18 at 22:52