Reputation:
Is there a way that I can make a program re-open itself when it closes?
I have this program that runs; and it gets a pop up; when you press okay it closes the program. I know I can start any executable with a batch, but how would I make it run all on it's own when it detects the program has closed?
I am able to start the program with this code:
@echo off
start "" "C:\Program Files (x86)\Winstep\WinstepXtreme.exe"
But I want this batch file to launch when WinstepXtreme.exe
terminates.
UPDATE: okay so the suggested code works but its activating non stop making the PC unable to do certain thing's, also the cmd window stay opne but i fixed that. in my process list there are two files: Nextstart.exe and Workshelf.exe, not sure if there is a code command where you can type, if "workshelf.exe" doe sent exist then start workshelf.exe? If Not Exist "%ProgramFiles(x86)%" Goto???
---------->[SOLUTION]<----------
@echo off
:Restart start "Edit Text" /wait "C:\Program Files (x86)\Winstep\WorkShelf.exe"
goto restart
adding workshelf.exe instead of winstep made it stable, winstep exe launches a) next start and b) workshelf, only needed workshelf to restart but i can add multiple directory's of thing's to restart if closed.
Upvotes: 6
Views: 22939
Reputation: 2080
A simple solution would be like below that kill your application and start again.
@taskkill /f /im WinstepXtreme.exe >nul
@timeout /t 3 /nobreak >nul
@start C:\"Program Files (x86)"\Winstep\WinstepXtreme.exe >nul
@echo restart complete
Upvotes: 0
Reputation: 2961
Adjust instances of cmd.exe to the .exe you wish to monitor and restart
@ECHO OFF
(
ECHO Set objWMIService = GetObject ("winmgmts:"^)
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO DO while proc.count ^> 0
ECHO Set proc = objWMIService.ExecQuery("select * from Win32_Process Where Name='cmd.exe'"^)
ECHO if proc.count ^< 1 then exit do
ECHO wscript.sleep 5000
ECHO loop
ECHO Set WshShell=createobject("wscript.shell"^)
ECHO WshShell.run "cmd.exe", 1, true
ECHO WshShell.run "%~0", 0, false
) >%TEMP%\MonitorEXE.vbs
Start %TEMP%\MonitorEXE.vbs
mshta vbscript:msgbox("cmd.exe launched. Monitoring active.",0,"Notification")(window.close)
exit
This Batch will create a vbs script that monitors the process, and restarts it Automatically If no instances of the process exist. In the event it has to restart a procces, A message Box is created to Notify that has occured, Then the batch file is called to restart the vbs Montior.
The batch runs Silently (After it's inital launch), and is closed until needed again to restart the .exe Only the notifications will appear.
The 'Sleep' in the monitoring vbs is Highly advised, as it dramatically reduces the CPU usage involved in calling the WMI Provider Host
Upvotes: 0
Reputation: 49216
A simple solution would be
@echo off
:Restart
start "Winstep Xtreme" /wait "C:\Program Files (x86)\Winstep\WinstepXtreme.exe"
goto Restart
The batch file remains open now all the time. The execution of the batch file is halted as long as Winstep Xtreme is running. Once this application terminates itself, the execution of the batch file continues with starting Winstep Xtreme again.
You hopefully do not use this batch file just to workaround the limitations of the trial version of Winstep Xtreme.
Upvotes: 6