Question

Do Loop with wait for vbscript

Asked by: brian_appliedcpu

How do I use

do
   Set WshShell = WScript.CreateObject("WScript.Shell")
   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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-05-31 at 21:07:49ID21008471
Tags

vbscript

Topics

Miscellaneous Programming

,

Windows Batch Scripting

Participating Experts
1
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VBScript
    For the life of me, I can't figure out how to make a VBScript that will detect the number of partitions I have on my computer. I intend to use this number in a loop for defragging the number of partitions on a computer. I have the loop working all fine and dandy, but can't g...
  2. WScript.Shell Question
    There's no Category for VBScript and or WScript or just Windows Scripting, so I'll ask it in here since I use ASP and I think someone here might know. I'm using: SET Comm = WScript.CreateObject("WScript.Shell") Comm.Run("DOS Command here") That's the co...
  3. newbie wshshell.run grief
    I am trying to get some asp / vbscript to perform a robocopy (nt resourse kit) to publish websites from a staging to a production web server. It is giving me a bit of troule though. strCurrentpath = Server.Mappath("\") strNewpath = right(strCurrentpath, (len(strCu...
  4. WshShell.run
    I need to run an e-mail alert daily so I am using WshShell to run an ASP page from SQL Server. This all works fine but I need to have basic authentication where the ASP page will reside. The problem I have is that the page won't run because of the popup window that occurs no...
  5. Using wscript.shell to launch an app from VBScript
    hi guys, Ive added a script behind a button on an Outlook form that launches an app if the Save & Close button is clicked. The problem is, the Run command fails on the wscript.shell object. It seems to be an issue with using a spae in the run string. ie. if I put "C...
  6. Simple Wscript.Shell question
    Hi I want to use WScript.shell Run command, to run a little EXE file on the server, like nslookup.exe , and then get all the results (what the EXE file returns) and show them in my page. As I am new to Windows Script Host, I don't know how to get the returned texts. I testes ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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.

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("WScript.Shell")
intReturn01 = WshShell.Run("DoSomething.VBS", 1, TRUE)
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-WithTimeout.vbs
==================================
'This will wait for a determined period for a script to finish
Dim WshShell, oExec
dim intReturn01, iCnt
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("C:\WINDOWS\System32\WScript.exe DoSomething.vbs")

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?

 

by: brian_appliedcpuPosted on 2004-06-01 at 13:12:03ID: 11206726

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.

 

by: jkozeePosted on 2004-06-01 at 13:52:57ID: 11207079

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("WScript.Shell")

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?

 

by: brian_appliedcpuPosted on 2004-06-02 at 10:27:13ID: 11214683

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.vbs"
Set oWshShell = WScript.CreateObject("WScript.Shell")

do
   intReturn01 = oWshShell.Run(strFile01, 1, TRUE)

   WScript.Sleep(15000) ' 3600000
loop

 

by: jkozeePosted on 2004-06-02 at 10:52:48ID: 11214954

Ok, now I'm lost.  Are you saying that you have a VBA application in Microsoft Excel that is now in the file "c:\working\test.vbs", and it does not run when you call it with the above code?

 

by: brian_appliedcpuPosted on 2004-06-02 at 11:34:23ID: 11215431

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?

 

by: jkozeePosted on 2004-06-02 at 11:54:26ID: 11215635

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.

 

by: jkozeePosted on 2004-06-02 at 11:57:36ID: 11215661

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-exchange.com/Programming/Q_20998303.html

Any luck getting that to work?

 

by: brian_appliedcpuPosted on 2004-06-02 at 12:24:36ID: 11215892

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.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Client_Conn;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM tblClient_Status WHERE (tblClient_Status.ConnState = 'yes') AND (tblClient_Status.PermanentConn = 'no')", objConnection, adOpenStatic, adLockOptimistic
   ' 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("TimeOfConn"))
'    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

 

by: jkozeePosted on 2004-06-02 at 12:45:20ID: 11216096

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.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Client_Conn;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM tblClient_Status WHERE (tblClient_Status.ConnState = 'yes') AND (tblClient_Status.PermanentConn = 'no')", objConnection, adOpenStatic, adLockOptimistic
   ' 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("TimeOfConn"))
'    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

 

by: jkozeePosted on 2004-06-02 at 13:15:04ID: 11216356

Brian,

I looked through the code and it looks fine after the changes that I made.  I tested the script and it runs fine for me.  Let me know if it is working for you.

 

by: brian_appliedcpuPosted on 2004-06-02 at 13:45:04ID: 11216608

That was it...I just removed the Function Main () and End Main and moved it around and it works fine.

Now how was I supposed to know that?
OK, how far is this from being able to convert it to an vba, if it is not already, and use visual studio to compile it into an executable?

 

by: jkozeePosted on 2004-06-02 at 13:59:31ID: 11216728

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.

 

by: brian_appliedcpuPosted on 2004-06-02 at 14:06:39ID: 11216787

You are the man.
Very Cool indeed.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...