Pause for a Minute

  • Comments posted to this topic are about the content posted at 0

  • If you do need to run the script near midnight, you could use:

    exitTime = DateAdd("s", 60, Now())

    Do While Now() < exitTime


    But: This script seems to peg the CPU usage at 100% until it finishes, which could cause a problem.

    An alternative for longer pauses on NT/2000/XP would be to use the "AT" command to schedule the script to run again, and use a command line parameter to indicate that the script should start at a specific point.


    Function ScheduleScript(strParam, lSeconds)

    'Schedule this script to run with the specified command in a number of seconds

    Dim dteRetry, strRetry, strCmd, lRet, Shell

    On Error Resume Next

    dteRetry = DateAdd("s", lSeconds, Now())

    If Hour(dteRetry)=0 Then

    strRetry = "12"

    ElseIf Hour(dteRetry)>12 Then

    strRetry = (Hour(dteRetry)-12)


    strRetry = Hour(dteRetry)

    End If

    strRetry = strRetry & ":" & Right("00" & Minute(dteRetry),2)

    If Hour(dteRetry)>=12 Then

    strRetry = strRetry & "pm"


    strRetry = strRetry & "am"

    End If

    strCmd = "AT " & strRetry & " /interactive " & Chr(34) & WScript.ScriptFullName & Chr(34)

    If Len(strParam) > 0 Then

    strCmd = strCmd & " /" & strParam

    End If

    lRet = -1

    Set Shell = WScript.CreateObject("WScript.Shell")

    lRet = Shell.Run(strCmd, 0, True)

    If Not(lRet=0) Then

    ScheduleScript = False


    ScheduleScript = True

    End If

    End Function

  • Hey Steve, in your discussion you mention the need to wait because of the dialog that appears when shutting down a service. Many people don't realize however that a service (especially a good one) should have been written for answer dialog issues. Usually, do a cmd line call like


    will handle this. Now your vendor of course may have been absolute idiots and don't support but may be a better solution than having to wait.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)


    WaitFor 1.0

    Does not use any cpu time, pauses ASP scripts nicely.

    Have been using it for unusual applications involving messaging. Highly recommend using this component :- its free and its never caused any problems.

    (dont forget to set your Timeouts )

  • Not bad! Couple ideas I can add. One is to avoid the limitations of the timer by using date and datediff. In VB you'd put a DoEvents inside your loop to give up processor time, doesnt look like it's supported in VBS. The "right" way to do this is to use the Sleep api which will pause the app and not use resources. In VB you can do it with an api call, no way that I know of in VBS. I think you can accomplish the same thing by using the Windows Scripting Host which has a sleep method.


  • Of course there is always the SQL Server way to wait: WAITFOR

    WAITFOR DELAY '00:01:00'

    The 1 line of code above in a stored procedure will wait for 1 minute before continuing.

    Joshua J. Beck

    Senior Application Architect



    “The more you say, the less people remember.”

    --Francois Fenelon

  • Lots of other solutions I know, but this one met our needs and worked nicely.

    Thanks for the suggestions.

    Steve Jones

  • Here's another one that I came across the other day. Documentation says it's supposed to take care of the midnight issue. (Apologies to the author of this code for no credit given -- forgot where I saw it.)

    Dim numberofsecs

    numberofsecs = 2

    msgbox "Before the pause"

    Call Pause(numberofsecs)

    msgbox "After the pause"

    Sub Pause (nSecond)

    Dim t0

    t0 = Timer

    Do While Timer - t0 < nSecond

    ' if we cross midnight, back up one day

    If Timer < t0 Then

    t0 = t0 - clng(24) * clng(60) * clng(60)

    End If


    End Sub

  • Is there a sleep function in VS script?

    in most of unix shell scrip (c, korn), you can sleep(60). that is it.

  • What about SQL's WAITFOR command?

  • The SQL command works well, but this particular process wasn't running on a SQL server. Instead it was a backup of another database (Btrieve).

    Steve Jones

  • Steve,

    as a total beginner, I found your script very simple and very useful.



Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply