Solved make a batch file that will relaunch a program if user close

January 25, 2012 at 10:58:40
Specs: Windows XP
how to relaunch a program if user close the program, i already have the script to start a program which is folowwing

@ECHO.
@ECHO Loading Premise Law Library...
@ECHO OFF
ping 192.168.1.2 -n 20 -w 1000 > nul
rem START "" "\\tst-ll\WestGroup\program files\West Group\Premise\winprs\WinPrs.exe"
start "" "\\tst-ll\WestGroup\program files\West Group\Premise\winprs\winprs.exe"
EXIT

Now i want to add a code where if user closes this program , it wshould automatically run that program again.


See More: make a batch file that will relaunch a program if user close

Report •

✔ Best Answer
January 30, 2012 at 14:59:12
I think I understand what Rajeshnayyar is referring to by bluescreen (not a BSOD, but rather the absence of explorer).

I would place the application path in your registry's shell line: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell

Then create a scheduled task that runs every 1 minute minimized to check that the program is running:

@echo off
tasklist | findstr /i WinPrs.exe
if %errorlevel% neq 0 goto restart
goto end
:restart
start "" "\\tst-ll\WestGroup\program files\West Group\Premise\winprs\winprs.exe"
:end
exit




#1
January 27, 2012 at 09:42:03
does winprs leave an exit code? if not you could make your own (have a batch file set an env var called status as running, call winprs.exe, then when the user closes the batch file, then generate the status envvar as closed.) just loop the batch and check for %status%.

gl


Report •

#2
January 27, 2012 at 12:24:59
Can you write the script for this, I am not good in scripting, also winprs.exe is an application, where user can close this application. We are running a batch file from Shell, so all the other windows services and program dont run but this batch file, once user close this application, they see a blue screen. I hope u understand what i am saying...

Report •

#3
January 27, 2012 at 19:08:33
just check the process list with batch and see if your program is running if not start it

then put a 1 second or more wait in between times it checks.

then make it also loop


ex:
@echo off
:check
tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" goto running

:running
:: This will have it wait about 1 second change "1000" to make it wait longer
PING 1.1.1.1 -n 1 -w 1000 >NUL
echo.
echo Checking if program is running..
echo.
cls
goto check

:not_running
cls
echo.
echo Starting program
echo.
start "your file"
goto check


I did not test this but im pretty sure it will work


Report •

Related Solutions

#4
January 29, 2012 at 14:22:01
Note: If the PC gets a BSOD when the application closes, there's not much a script can do.
@ECHO.
@ECHO Loading Premise Law Library...
@ECHO OFF
ping 192.168.1.2 -n 20 -w 1000 > nul
:loop
start /wait "" "\\tst-ll\WestGroup\program files\West Group\Premise\winprs\winprs.exe"
goto loop

How To Ask Questions The Smart Way


Report •

#5
January 30, 2012 at 14:59:12
✔ Best Answer
I think I understand what Rajeshnayyar is referring to by bluescreen (not a BSOD, but rather the absence of explorer).

I would place the application path in your registry's shell line: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell

Then create a scheduled task that runs every 1 minute minimized to check that the program is running:

@echo off
tasklist | findstr /i WinPrs.exe
if %errorlevel% neq 0 goto restart
goto end
:restart
start "" "\\tst-ll\WestGroup\program files\West Group\Premise\winprs\winprs.exe"
:end
exit



Report •

#6
January 31, 2012 at 11:52:37
you are absolutely right...., i am going to try your script and let you know, also rather that putting the the application path in the Shell, I am putting the batch file path in the shell as i need to run one more than one application in the shell mode.
Thanks for your help.

Report •

Ask Question