I actually want the script to run "cylcle thru the script" then pausing for 5 or 10 minutes and then run again pause and again pause...forever.
Main Topics
Browse All TopicsHow do I use
do
Set WshShell = WScript.CreateObject("WScr
intReturn01 = WshShell.Run(strFile01, 1, TRUE)
x=1
WScript.Sleep(3600000)
loop
to start a vbscript? Do I put this inside of the script or in an external vbs that calls my script?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In that case, you would put your original posting in a separate VBS file and use it to call the script that does something.
==========
DoSomething.vbs
==========
'Do something useful then exit
=============
CallDoSomething.vbs
=============
Dim strFile01, oWshShell
strFile01="DoSomething.vbs
Set oWshShell = WScript.CreateObject("WScr
do
intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
'x=1 'What purpose does this serve???
WScript.Sleep(300000) 'This will sleep 5 Minutes, after the called script has returned, so it will be run every 5 minutes plus the length of time it took to run last time
loop
If you don't want to have a separte vbs, then just make the DoSoemthing code a sub routine. Call it, sleep and call it again
do
DoSomething
WScript.Sleep(300000) 'Take 5
loop
WScript.Quit 'We will never get here
Sub DoSomething()
'Do Something Useful
End Sub
Does this answer your original question?
OK so I have this now but it appears that although my main script runs fine in the Excel it does not run thru cscript or wscript. Any ideas?
Dim strFile01, oWshShell
strFile01="c:\working\test
Set oWshShell = WScript.CreateObject("WScr
do
intReturn01 = oWshShell.Run(strFile01, 1, TRUE)
WScript.Sleep(15000) ' 3600000
loop
I am a real newbie, so please be patient with me....
I wrote a vbscript pasted it into a module in the Microsoft Visual Basic "whatever" that is in Excel by pressing the Alt-F11.
Ran the code and worked at it until it worked.
I would now like to execute the code from either wscript or cscript if possible.
I also have visual studio 6 enterprise edition that i have never used so i guess i can convert my vbscript to vba (or so Ive read) and then make it into an exe?
Everyone was a newbie at somepoint, so I always try to be patient.
There is not enough information for me to help. There is no code posted to evaluate, so there is no way for me to comment on what is causing the problem. Not that it matters that much, your code that was written in Excel is Visual Basic for Applications (VBA). VB, VBA, and VBS (run through a script interpretter cscript or wscript) have subtle differences that may need to be worked out.
If you run the vbs, does wscript give you a line number where the error occured or any hints as to what went wrong. Are you sure that you aren't using any variable types that are only in Excel. Make sure that any objects are declared as variants (Dim oObj with no as object), and that they are instantiated with the CreateObject method.
Let me know the offending line and post some code so we can have a look.
PS Did you check out my response to your question "SSH or Telnet Script Needed in either JScript or VBScript no wscripting" at http://www.experts-exchang
Any luck getting that to work?
OK Here is the code...
I have commented out the msgbox. Basically I am just trying to modify a database based on time.
Sub ExamineDB(LocalIP, remoteIP, LockOutTime, TimeOfConn)
remoteIP = ""
strremoteIP = remoteIP
Dim timetolock 'As Single
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connec
Set objRecordset = CreateObject("ADODB.Record
objConnection.Open "DSN=Client_Conn;"
objRecordset.CursorLocatio
objRecordset.Open "SELECT * FROM tblClient_Status WHERE (tblClient_Status.ConnStat
' strremoteIP = objRecordset("remoteIP")
'" & remoteIP & "'", objConnection, adOpenStatic, adLockOptimistic
Do While Not objRecordset.EOF
strLockOutTime = objRecordset("LockOutTime"
remoteIP = objRecordset("remoteIP")
' MsgBox "remoteIP is " & remoteIP
LocalIP = objRecordset("LocalIP")
' MsgBox "LocalIP is " & LocalIP
TimeOfConn = objRecordset("TimeOfConn")
' MsgBox "TimeOfConn is " & TimeOfConn
CalcCurrentTime = CDbl(Date) + CDbl(Time)
' MsgBox "CalcCurrentTime is " & CalcCurrentTime
CalcTimeOfConn = CDbl(objRecordset("TimeOfC
' MsgBox "CalcTimeOfConn is " & CalcTimeOfConn
LockOutTime = strLockOutTime
' MsgBox "LockOutTime is " & LockOutTime
ConnMin = LockOutTime / (60000)
' MsgBox "ConnMin is " & ConnMin
timetolock = ConnMin / (1440) ' This is the fraction of the day
' MsgBox "timetolock is " & timetolock
TimeToExpire = (CalcTimeOfConn + timetolock)
' MsgBox "TimeToExpire is " & TimeToExpire
ActualTimeToExpire = CDate(TimeToExpire)
' MsgBox "ActualTimeToExpire is " & ActualTimeToExpire
If CalcCurrentTime > TimeToExpire Then
TimeIsExpired = "Yes"
' Call the No Conn Sub Routine
'NoConn remoteIP, LocalIP
ConnState = "no"
strConnState = ConnState
objRecordset("ConnState") = strConnState
objRecordset.Update
Else
TimeIsExpired = "No"
End If
' MsgBox "TimeIsExpired is " & TimeIsExpired
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
End Sub
Function Main()
' Set the return value to OK
Main = "OK"
Dim LockOutTime
Dim remoteIP ' Offending IP Address
Dim LocalIP ' IP of Local Sending Message
Dim ConnState
Dim PermanentConn
Dim DateOfMessage
Dim TimeOfMessage
' **********Zero Out Everythin
remoteIP = ""
LocalIP = ""
' Call the Sub Routine to look at the Database
ExamineDB LocalIP, remoteIP, LockOutTime, TimeOfConn
Main = "OK"
End Function
Brian,
Before I go throught the code line-by-line, let me get a few things out of the way.
If this is the actual vbs script, it will not work because vbs doesn't use the sub main(). It is a scripting language, so it just processes the file from the begining. Move the sub main code to the front of the code and remove Sub Main() and End sub. I have quickly moved the code around, without looking at the code. Here it is give it a try, and let me know if it works. It should at least start up now. It probably wasn't doing anything-correct?
'Function Main()
' Set the return value to OK
Main = "OK"
Dim LockOutTime
Dim remoteIP ' Offending IP Address
Dim LocalIP ' IP of Local Sending Message
Dim ConnState
Dim PermanentConn
Dim DateOfMessage
Dim TimeOfMessage
' **********Zero Out Everythin
remoteIP = ""
LocalIP = ""
' Call the Sub Routine to look at the Database
ExamineDB LocalIP, remoteIP, LockOutTime, TimeOfConn
Main = "OK"
WScript.Quit
'End Function
Sub ExamineDB(LocalIP, remoteIP, LockOutTime, TimeOfConn)
remoteIP = ""
strremoteIP = remoteIP
Dim timetolock 'As Single
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connec
Set objRecordset = CreateObject("ADODB.Record
objConnection.Open "DSN=Client_Conn;"
objRecordset.CursorLocatio
objRecordset.Open "SELECT * FROM tblClient_Status WHERE (tblClient_Status.ConnStat
' strremoteIP = objRecordset("remoteIP")
'" & remoteIP & "'", objConnection, adOpenStatic, adLockOptimistic
Do While Not objRecordset.EOF
strLockOutTime = objRecordset("LockOutTime"
remoteIP = objRecordset("remoteIP")
' MsgBox "remoteIP is " & remoteIP
LocalIP = objRecordset("LocalIP")
' MsgBox "LocalIP is " & LocalIP
TimeOfConn = objRecordset("TimeOfConn")
' MsgBox "TimeOfConn is " & TimeOfConn
CalcCurrentTime = CDbl(Date) + CDbl(Time)
' MsgBox "CalcCurrentTime is " & CalcCurrentTime
CalcTimeOfConn = CDbl(objRecordset("TimeOfC
' MsgBox "CalcTimeOfConn is " & CalcTimeOfConn
LockOutTime = strLockOutTime
' MsgBox "LockOutTime is " & LockOutTime
ConnMin = LockOutTime / (60000)
' MsgBox "ConnMin is " & ConnMin
timetolock = ConnMin / (1440) ' This is the fraction of the day
' MsgBox "timetolock is " & timetolock
TimeToExpire = (CalcTimeOfConn + timetolock)
' MsgBox "TimeToExpire is " & TimeToExpire
ActualTimeToExpire = CDate(TimeToExpire)
' MsgBox "ActualTimeToExpire is " & ActualTimeToExpire
If CalcCurrentTime > TimeToExpire Then
TimeIsExpired = "Yes"
' Call the No Conn Sub Routine
'NoConn remoteIP, LocalIP
ConnState = "no"
strConnState = ConnState
objRecordset("ConnState") = strConnState
objRecordset.Update
Else
TimeIsExpired = "No"
End If
' MsgBox "TimeIsExpired is " & TimeIsExpired
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
End Sub
We're getting into a lot of unrelated questions to the original posting, but in a nutshell you were closer to a VB exe with the original VBA code that you posted.
Start VB, choose standard exe.
Right Click on Form1 in the project explorer and choose remove form1
Right click in project explorer and choose add->module->new
Paste in the Original VBA code that you posted.
Change Function Main to Sub Main and End Function to End Sub
remove Main = "OK" lines (no longer a function)
Compile to exe.
Business Accounts
Answer for Membership
by: jkozeePosted on 2004-06-01 at 12:48:08ID: 11206507
I'm not sure what you are asking for, but I'll make a guess.
ipt.Shell" ) VBS", 1, TRUE)
======== eout.vbs ======== l")
System32\W Script.exe DoSomething.vbs")
Let's assume that you have a script that takes some time to finish. For our purpose we'll create a script called DoSomething.vbs that simply sets it's ExitCode to the user response of a MsgBox
===============
DoSomething.vbs
===============
'Just set the ExitCode with the response of a MsgBox
WScript.Quit MsgBox("Return the answer to this MessageBox",vbYesNoCancel)
Now we want to run this script from another script and wait for it to finish, then we can process based on it's ExitCode
======================
WaitForDoSomething.vbs
======================
'This will wait indefinately for a script to finish
Set WshShell = WScript.CreateObject("WScr
intReturn01 = WshShell.Run("DoSomething.
Select Case intReturn01
Case vbYes
MsgBox "Yes Selected"
Case vbNo
MsgBox "No Selected"
Case vbCancel
MsgBox "Cancel Selected"
End Select
Now suppose you want a timeout to occur, you could do something like this
==========================
WaitForDoSomething-WithTim
==========================
'This will wait for a determined period for a script to finish
Dim WshShell, oExec
dim intReturn01, iCnt
Set WshShell = CreateObject("WScript.Shel
Set oExec = WshShell.Exec("C:\WINDOWS\
Do While oExec.Status = 0
WScript.Sleep 1000 'Sleep 1 second
iCnt = iCnt + 1
If iCnt > 10 then Exit Do 'Wait for ten seconds, then give up
Loop
intReturn01 = oExec.ExitCode
Select Case intReturn01
Case vbYes
MsgBox "Yes Selected"
Case vbNo
MsgBox "No Selected"
Case vbCancel
MsgBox "Cancel Selected"
Case Else
MsgBox "Got tired of waiting..."
End Select
Is this what you are after?