Link to home
Start Free TrialLog in
Avatar of NST-LI
NST-LI

asked on

Batch script to restart program if it closes.

We host a server that runs a program(rather than service) with a gui at the desktop that cannot be closed. Recently, we have been having issues where it has been closing which is a big problem. Is there a batch script that can be created to start the program if it is closed automatically?

Thanks
Avatar of AmazingTech
AmazingTech

You could setup a Scheduled Task every x minutes to check if your program is not running then start it.

Set ProgramPath=C:\Windows
Set ProgramName=Regedit.exe
 
tasklist /FI "IMAGENAME eq %ProgramName%" | find /i "%ProgramName%"
 
if errorlevel 1 Start "Starting %ProgramName%" "%ProgramPath%\%ProgramName%"

Open in new window

Avatar of NST-LI

ASKER

TY for your response AmazingTech,

I have created a batch script using your code and tested on my PC with a random program. I set a scheduled task to run every 10 minutes and the result was a new instance of the program(VLC Player was the test subject) was created. I actually don't understand the code so I can't tell what does what in each line. I have attached some screenshots of what I have done if your curious.

script.bmp
batchscript.bmp
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial