One solution is to use a batch file with an infinite
for loop to automatically restart the application if it closes. There are two possibilities here, depending on how the application is designed.
If the application is launched and runs in the same process, you can use a very simple batch file:
:: Wait 30 seconds before restarting.
TIMEOUT /T 30
This will run infinitely. Any time
application.exe is closed or crashes, the batch file will restart it.
This will not work if
subapp.exe and then
application.exe closes. In this case, you would need something more complicated.
:: Uncomment the following line on versions of Windows prior to Windows 7 and comment out the TIMEOUT line. The PING solution will not be 100% accurate with _PolingInterval.
:: PING 127.0.0.1 -n %_PollingInterval% >nul
TIMEOUT /T %_PollingInterval%
FOR /F "tokens=2 delims= " %%i IN ('TASKLIST ^| FIND /i "subapp.exe"') DO SET PID=%%i
IF [%PID%]== (
ECHO Application was not running. Restarting script.
If your application could have various processes, then you can probably use something like
FINDSTR /i "subapp.exe application.exe" instead of
FIND /i "subapp.exe", but this wouldn't work for processes with spaces in their name as
FINDSTR uses the space as a deliminator.
In order to stop these batch files once they've been started, leave the application open and switch to the command prompt. Then use Ctrl + C and acknowledge you want to end the script. Once the script is terminated, close the application.