How to restart the program automatically if it crashes in Windows?

How to start a program automatically if it works on a Windows 2003 server? Sometimes my program just crashes, is there a way in Windows or the settings that I can set?

+6
source share
6 answers

The usual approach is to start the so-called guardianship process. This is a separate process, often a service that monitors the state of the main process. When the guardian discovers that the main service is dead, she restarts it.

As far as I know, there are no built-in functions in Windows to do this for you.

+7
source

Please note: running self-closing bit files can be useful, but if you don’t know what you are doing, they can cause all kinds of chaos. This is especially important if you run them at startup. You have been warned.

Anyway. I just remembered something from my 286 days when I played a lot with BAT files. If you write a file

yourprogram.exe some other event 

the BAT file will start your program, and then pause and wait in the background until the program exits. After that, he will launch "some other event." Previously, it was annoying if you wanted to run several things at once, but here it is really useful. Using this, you can make it run a loop that restarts the program (and re-runs the bat file) as soon as it exits. Combine this with https://superuser.com/questions/62525/run-a-completly-hidden-batch-file and you won’t even see how this happens.

The last BAT file ("restart.bat" in this example) will look something like this:

 c:\[location]\yourprogram.exe wscript "C:\[location]\invisible.vbs" "C:\[location]\restart.bat" 

What about that. Run the program (when starting through a task or even just the startup folder) with line 2, and this should solve your problem :)

Oh, if you want to stop the loop, simply rename the bat file or put "//" in front of two lines, save it and exit the program.

If you need administrator privileges to run the program, I found a solution using psexec ( http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx ) to run both programs and the bat with elevated privileges. In this case, the BAT will look like this:

 c:\[location]\psexec -hc:\[location]\yourprogram.exe c:\[location]\psexec -h wscript "C:\[location]\invisible.vbs" "C:\[location]\restart.bat" 

Then you run bat as an administrator or run the second line (without the psexec part) from the elevated task scheduler. CAUTION: running it as a regular user and clicking “no” at the UAC prompt, I got a BSOD, perhaps because it was looping “cannot run the program due to lack of privileges” a couple of billion times or something like that :)

+3
source

Unfortunately, there are no settings in Windows to automatically restart a regular program when it crashes.

Do you need to actively interact with the application GUI? Some of the Service Wrappers (designed to run any application as a Windows service) will track your application and restart it if it crashes, but be sure to examine Session Isolation 0 to ensure that it does not interfere.

+1
source

You can use a special application, for example BDV SystemEvents or any other. It allows you to specify the application that will be launched if any other application is closed. Indicate the same application as the Condition, and as the action, and you will get the expected results.

+1
source

I was looking for something similar. There are two ways to deal with this: either you can write a small script yourself, or use an existing one.

After some googling, I came across this nice list . The blogger has put together about 8 tools to automatically restart a broken or closed application.

+1
source

You can use RegisterApplicationRestart.

"If you register for a reboot and the application encounters an unhandled exception or does not respond, the user is offered the option to restart the application; the application does not automatically restart without user consent."

To automatically restart without user intervention, RestartOnCrash also exists. Works with all versions of Windows.

+1
source

Source: https://habr.com/ru/post/908794/


All Articles