Someone here asked once how to tell if a process has stopped & to either restart it, or start another process once that one ended...
(I suggested writing an .exe file that checks for existing hWnds (Window Handles) but that didn't wash to well since the person was not a coder of executeables...)
SO, Here are some USEFUL batchfiles for task scheduler for this (as well as checking if a task succeeded or failed) that I stumbled upon today @ www.jsiinc.com/reghack.htm you guys may find useful (especially network folks):
6220 » How can I 'schedule' a process to start as soon as it stops?
If you need to cause a process to start as soon at it stops, use the %0 batch parameter.
The %0 parameter contains the name of the invoked process, regardless of how it was invoked; i.e., by the scheduler, a batch, a shortcut, a program, or the Run command.
Here is an example of Continuous.bat:
@echo off
setlocal
set this=%0
YourProgram.exe
endlocal&%this%
HERE IS ONE THAT CHECKS IF A PROCESS SUCCEEDED OR FAILED DURING A SCHEDULED RUN:
4663 » How can I be notified of failed Scheduled Tasks?
To automatically be notified of failed Scheduled Tasks, I have scripted Schedlgu.bat. The syntax is:
Schedlgu [%ComputerName%]
where %ComputerName% is the computer that will receive the alert of the failed task. If you omit this parameter, the local computer will receive the alert.
NOTE: You can easily modify this script to send the alert to a list of computer and/or user names, or to a group.
NOTE: Schedlgu.bat records the failed events at "%APPDATA%\schedlgu.txt", to prevent the sending of duplicate alert messages.
Schedlgu.bat should be scheduled as a background task. When I create the schedule, I set it to run daily and start yesterday and run every 10 minutes from 00:00 to 23:49.
Schedlgu.bat contains:
@echo off
setlocal
set notify="%computername%"
if not {%1}=={} set notify=%1
set job=
set done=N
if exist "%temp%\schedlgu.tmp" del /q "%temp%\schedlgu.tmp"
if exist "%temp%\schedlgu1.tmp" del /q "%temp%\schedlgu1.tmp"
if exist "%temp%\schedlgu2.tmp" del /q "%temp%\schedlgu2.tmp"
if exist %temp%\schedlgu.txt del /q %temp%\schedlgu.txt
if not exist "%APPDATA%\schedlgu.txt" @echo ** Begin Schedulgu.bat **>"%APPDATA%\schedlgu.txt"
copy %systemroot%\schedlgu.txt %temp%\schedlgu.txt
for /f "Tokens=*" %%i in ('type %temp%\schedlgu.txt') do set line=%%i&call

arse
if not exist "%temp%\schedlgu.tmp" goto :EOF
for /f "Tokens=*" %%i in ('type "%APPDATA%\schedlgu.txt"') do set line=%%i&call :small
findstr /L /I /V /G:"%TEMP%\schedlgu2.tmp" "%temp%\schedlgu.tmp" >>"%TEMP%\schedlgu1.tmp"
for /f "Tokens=*" %%i in ('type "%TEMP%\schedlgu1.tmp"') do set line=%%i&call :sendit
del /q "%temp%\schedlgu.tmp"
del /q "%temp%\schedlgu1.tmp"
del /q "%temp%\schedlgu2.tmp"
endlocal
goto :EOF
:small
set line=%line:~0,99%
@echo %line%>>"%TEMP%\schedlgu2.tmp"
goto :EOF
:sendit
net send %notify% "%line%">nul
@echo %line%>>"%APPDATA%\schedlgu.txt"
goto :EOF

arse
set line=%line:"=#%
set line=%line

=[%
set line=%line

=]%
set line=%line:"=*%
if "%line:~0,1%" EQU "*" goto :EOF
if "%done%" EQU "Y" goto :EOF
if "%line:~0,1%" EQU "#" goto start
if "%line%"=="[ ***** Most recent entry is above this line ***** ]" set done=Y&goto start
set job=%job%{%line%}
goto :EOF
:start
if "%job%"=="" goto new
if "%job:~0,1%" EQU "Y" goto write
set work=%job:{Started =%
if NOT "%work%" EQU "%job%" goto new
set work=%job:{Result: The task completed with an exit code of [0].}=%
if NOT "%work%" EQU "%job%" goto new
set work=%job:#Task Scheduler Service#{Exited at=%
if NOT "%work%" EQU "%job%" goto new
:write
set job=%job:#= %
@echo %computername% %job%>>"%temp%\schedlgu.tmp"
:new
for /f "Tokens=1-3* Delims=#*" %%j in ('@echo %line%') do set p3=%%l
set job=N
if /i "%p3%" EQU " ERROR " set job=Y
if /i "%p3%" EQU " WARNING " set job=Y
set job=%job%%line%
Here are some sample alerts:
JSI005 Y At2.job [CMD.EXE /K] 12/31/2001 2:37:00 PM ** ERROR **
{Unable to start task.}{The specific error is:}
{0x80070002: The system cannot find the file specified.}
{Try using the Task page Browse button to locate the application.}
JSI005 Y getprod.job [] 12/31/2001 2:53:04 PM ** WARNING **
{Unable to load task.}{The specific error is:}
{0x80070005: Access is denied.}
{Try using the Task page Browse button to locate the application.}
JSI005 N At1.job [CMD]{Finished 12/31/2001 3:14:39 PM}
{Result: The task completed with an exit code of [c000013a].}
NOTE: After the computer name, the 1st character is Y for an ERROR or WARNING,
or a N for a non-zero exit code.
How to be notified if a Scheduled Task is missed.
If you computer is unavailble to run a scheduled task, you can configure Scheduled Tasks to notify you of the missed task:
1. Open Scheduled Tasks.
2. On the Advanced menu, select Notify Me of Missed Tasks.
The next time a task is missed, you will receive a pop-up warning, and an offer to run the missed tasks.
How to view the results of Scheduled Task processing.
2911 » Scheduled Tasks exit/results codes.
The exit codes returned in the %systemroot%\schedlgu.txt file, or via Scheduled Tasks / Advanced / View Log, are the status codes returned from the scheduled task. The general syntax is:
Job1.job" (test.bat)
Finished 4/26/2000 2:10:00 AM
Result: The task completed with an exit code of (xx).
The most common exit codes are:
0 or 0x0: The operation completed successfully.
1 or 0x1: Incorrect function called or unknown function called.
10 or 0xa: The environment is incorrect.
0xC000013A: The application terminated as a result of a CTRL+C.
NOTE: The C indicates an error condition.
When the Task Scheduler has a problem running the job, you get a result code like:
"badjob.job" (causesanerror.bat) 6/29/2000 10:47:00 AM ** ERROR **
Unable to start task.
The specific error is:
0x80070002: The system cannot find the file specified.
Try using the Task page Browse button to locate the application.
* That site's a GOLDMINE for networking folks who do alot of logon scripting for gathering information & status of things as well as scheduling tasks etc. as shown above...
(In addition to that, that place is LOADED with commandlines freewares (console mode DOS type character mode apps) that you can use in said scripts that extend the HECK outta native batch language & reskit commandlines tools... WITH THESE BATCHES AS WELL TO USE THEM IN PRACTICAL USEFUL APPLICATION for you all!)
APK
P.S.=> Highly recommended for networking personnel, a real time saver with prebuilt batches for TONS of cool purposes (especially the ones there that have SETLOCAL, ENDLOCAL, FOR & IF EXIST commands).
That site's saved me time in writing my own commandline console mode apps in Delphi first of all since tools already exist WITH batches for practical use that work as well... apk