greetrufus
asked on
Restart a failed program
I am running Mercury mail on my windows PC.
Occasionally it will stop running.
I need a script that I can schedule to run every 30 minutes that will:
1. check the running processes for mercury.exe
2. If mercury.exe is in the running processes, do nothing and go back to sleep
3. If mercury.exe is not found in the running prcesses, restart mercury.exe (i.e. c:\mercury\mercury.exe)
4. Rerun step 2
4. Output actions to a log file
Any suggestions?
Occasionally it will stop running.
I need a script that I can schedule to run every 30 minutes that will:
1. check the running processes for mercury.exe
2. If mercury.exe is in the running processes, do nothing and go back to sleep
3. If mercury.exe is not found in the running prcesses, restart mercury.exe (i.e. c:\mercury\mercury.exe)
4. Rerun step 2
4. Output actions to a log file
Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like...
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileName, fso, f, lines
fileName = "c:\someLog.txt"
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shel l")
' launch it...
Set f = fso.OpenTextFile(fileName, ForAppending, True)
Set oExec = WshShell.Exec("calc")
f.Write(Now & " Application Started" & vbCrLf)
f.Close
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
While True
' check every 5 seconds to see if our targetTime has been passed
While targetTime > Now
WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
Wend
' if it's closed...run it again
Set f = fso.OpenTextFile(fileName, ForAppending, True)
If oExec.Status <> 0 Then
Set oExec = WshShell.Exec("calc")
f.Write(Now & " Application Restarted" & vbCrLf)
Else
f.Write(Now & " Application Still Alive" & vbCrLf)
End If
f.Close
' set next "event" for 30 minutes out...
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileName, fso, f, lines
fileName = "c:\someLog.txt"
Set fso = CreateObject("Scripting.Fi
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shel
' launch it...
Set f = fso.OpenTextFile(fileName,
Set oExec = WshShell.Exec("calc")
f.Write(Now & " Application Started" & vbCrLf)
f.Close
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
While True
' check every 5 seconds to see if our targetTime has been passed
While targetTime > Now
WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
Wend
' if it's closed...run it again
Set f = fso.OpenTextFile(fileName,
If oExec.Status <> 0 Then
Set oExec = WshShell.Exec("calc")
f.Write(Now & " Application Restarted" & vbCrLf)
Else
f.Write(Now & " Application Still Alive" & vbCrLf)
End If
f.Close
' set next "event" for 30 minutes out...
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend
ASKER
How do I set the path to the executable?
it is c:\mercury\mercury.exe
Here is the code I am using that i get a path error on:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileName, fso, f, lines
fileName = "c:\Log.txt"
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shel l")
' launch it...
Set f = fso.OpenTextFile(fileName, ForAppending, True)
Set oExec = WshShell.Exec("c:\mercury\ mercury.ex e")
f.Write(Now & " Application Started" & vbCrLf)
f.Close
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
While True
' check every 5 seconds to see if our targetTime has been passed
While targetTime > Now
WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
Wend
' if it's closed...run it again
Set f = fso.OpenTextFile(fileName, ForAppending, True)
If oExec.Status <> 0 Then
Set oExec = WshShell.Exec("c:\mercury\ mercury.ex e")
f.Write(Now & " Application Restarted" & vbCrLf)
Else
f.Write(Now & " Application Still Alive" & vbCrLf)
End If
f.Close
' set next "event" for 30 minutes out...
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend
it is c:\mercury\mercury.exe
Here is the code I am using that i get a path error on:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileName, fso, f, lines
fileName = "c:\Log.txt"
Set fso = CreateObject("Scripting.Fi
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shel
' launch it...
Set f = fso.OpenTextFile(fileName,
Set oExec = WshShell.Exec("c:\mercury\
f.Write(Now & " Application Started" & vbCrLf)
f.Close
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
While True
' check every 5 seconds to see if our targetTime has been passed
While targetTime > Now
WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
Wend
' if it's closed...run it again
Set f = fso.OpenTextFile(fileName,
If oExec.Status <> 0 Then
Set oExec = WshShell.Exec("c:\mercury\
f.Write(Now & " Application Restarted" & vbCrLf)
Else
f.Write(Now & " Application Still Alive" & vbCrLf)
End If
f.Close
' set next "event" for 30 minutes out...
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend
ASKER