
Rerun a program automatically in wsh if it dies or is shutdown
Quote:
> Hi (im a newbie, please forgive),
> I am trying to write a small vbs (wsh) script that respawns a program
> if it is terminated...for example: if I run notepad.exe from the
> script I want the script to go to sleep (or checks every 10 seconds or
> so) until the program is killed or dies and then reexecutes the
> program (notepad.exe).
Hi
Here is a WMI\VBScript solution:
Set oShell = CreateObject("WScript.Shell")
Set oWmi = GetObject("winmgmts:")
' start notepad task
oShell.Run "notepad.exe"
' Waiting for solitaire to disappear
Do While True
sWmiq = "select Name from Win32_Process where name='notepad.exe'"
Set oQResult = oWmi.Execquery(sWmiq)
If oQResult.Count = 0 Then
' start notepad task again
oShell.Run "notepad.exe"
End If
WScript.Sleep 1000
Loop
--
torgeir