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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run for an hour and exit

Status
Not open for further replies.

Finnerbahce

Technical User
Sep 29, 2005
12
IE
How can i get a vbs script to run for an hour and exit. It's currently running every two minutes but I want it to run every two minutes for one hour.
 
>...but I want it to run every two minutes for one hour.
[tt]
callee="d:\xyz\abc.vbs" 'your main vbs

interval=2*60 'sec
duration=1*60*60 'sec

count=-1
do while count<duration\interval
count=count+1
createobject("wscript.shell").run "cscript.exe //nologo //b " & callee,0,false
if count<duration\interval then wscript.sleep interval*1000
loop
[/tt]
 
And where would this go in my script?

Option explicit
Dim IE, sLoop, sLoop2, isOperationComplete, dState, sList, sError
Sub objIE_NavigateError(pDisp,URL,TargetFrameName,StatusCode,Cancel)
' wscript.echo now() & " Error " & StatusCode & " accessing " & URL
wscript.echo now() & " Test FAILURE"
logfile.writeline now() & " Test FAILURE"
wshshell.run "c:\ringin.bat"
logfile.writeline now() & " Document Experienced Difficulty While Loading. Please Investigate."
wshshell.popup "Document failed to load. Please Investigate",15
createobject("wscript.shell").run "test.bat"
logfile.close
ie.quit
' ieErr=true
End Sub


Function Wait()
sError = 1
Do while IE.busy
wscript.sleep 1000
sError = sError + 1
Loop
if sError > 20 then
exit Function
end if
dState = IE.document.readystate

while (dState <> "complete" and sError < 20)
Wscript.sleep 1000
dState = IE.document.readystate
sError = sError + 1
wend
' *************IF INTERNET EXPLORER PAGE FAILS TO OPEN
if ieErr then 'navigation error
logfile.writeline now() & " Document failed to load. Please Investigate."
wshshell.run "c:\ringin.bat"
wshshell.popup "Document failed to load. Please Investigate",15
createobject("wscript.shell").run "test.bat"
ie.quit
***********************This is where I want to test this and if the error occurs 5 times then call sendmail.bat
end if
end function

'**************CREATE LOGFILE AND AMEND/APPEND
dim wshshell, fso , slog , logfile
dim ieErr : ieErr=false 'global scope added 20/07/05

slog = "c:\log\Test" & Right("0" & Day(Date), 2) & Right("0" & Month(Date), 2) & Year(Date) & ".log"

set wshshell=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
sLoop = "forever"
dState = ""
Do while sLoop = "forever"
sLoop2 = "forever"
Do while sLoop2 = "forever"
set logfile=fso.opentextfile(slog,8,true)

'************ HTTP CHECKER
set IE=Wscript.CreateObject("InternetExplorer.Application","objIE_")
IE.Navigate(" IE.visible = True
wait()


'Added by Finner, 8 Jul 2005. Populates the correct fields.
IE.document.getElementByID("VRM").value = "1234567" 'this is the VRM field
'IE.document.getElementByID("V5RefNo").value = "1" 'this is the V5 field
IE.document.getElementByID("TestNumber").value = "111222333444" 'this is the Test Number field
IE.document.getElementByID("cmdSubmit").click
wait()
if sError <= 50 then
wscript.echo now() & " Test OK"
logfile.writeline now() & " Test OK"
logfile.close
ie.quit
exit do
else

wscript.echo now() & " Test FAILURE"
logfile.writeline now() & " Test FAILURE"
wshshell.run "c:\ringin.bat"
logfile.writeline now() & " Document Experienced Difficulty While Loading. Please Investigate."
wshshell.popup "Document failed to load. Please Investigate",15
createobject("wscript.shell").run "test.bat"
logfile.close
ie.quit
***********************This is also where I want to test this and if the error occurs 5 times then call sendmail.bat
end if
exit do
'************ End of HTTPS Check
sLoop2 = "done"
Loop
'Wait for 15 Minutes
Wscript.Sleep 900000
Loop

P.S. Thanks to NetNodeMan for the code.
 
>And where would this go in my script?
Take out the outer repetitive loop, the loop which main reason of existence is to do anew and repeat the same functionality---I don't read into detail of the script, you have to identify which loop it is, probably the outer loop. Then, the strip-down script corresponds to my calling abc.vbs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top