Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program monitor

Status
Not open for further replies.
Sep 12, 2002
282
SG
hi,
can i know is it possible to monitor if an application closes and automatically restarts it ?
thanks
 
sentmemail,

A quick and dirty way to do it is to use TLIST from the Win2K support tools.

For example, say we have a program called DIRCMD. TLIST with the -p option will return the PID if it's running or -1 if it's not.

So we could use this to check:

set dircmd=
for /f "tokens=1" %%a in ('tlist -p dircmp') do set dircmd=%%a
if [%dircmd%]==[-1] echo not running !!


Ian

Everyday the Computer Gods pick one person to be "it". Maybe, today is your day !!
 
but TLIST does not restart the program if it closes, right?
 
sentmemail,

TLIST is just the means to the end. I would start the program in question instead of just printing "not running" and add a call to the ST sleep command so that the batch file loops after sleeping.

So my batch file now looks like this:-

@echo off
:top
set dircmd=
for /f "tokens=1" %%a in ('tlist -p dircmp') do set dircmd=%%a
if [%dircmd%]==[-1] dircmp
rem sleep one hour
sleep 3600
goto top

Or you could set up a Sceduled Task to run the program every so often and not bother with the sleep statement and the goto top


Ian

Everyday the Computer Gods pick one person to be "it". Maybe, today is your day !!
 
in this case i need to make sure that no one closes the cmd window right?
 
sentmemail,

The quickest way to do that would be to run it from Scheduled Tasks with a startit batch file that calls a checkapp batch file like this:-

startit.bat

@echo off
start /min checkapp.bat
exit

checkapp.bat

@echo off
set dircmd=
for /f "tokens=1" %%a in ('tlist -p notepad') do set dircmd=%%a
if [%dircmd%]==[-1] notepad
exit

If you run this from ST, you will see a very brief flash as the batch files run and then notepad will open

Ian

Everyday the Computer Gods pick one person to be "it". Maybe, today is your day !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top