Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay in VB Script?

How can I delay a Vb Script? The following codes did not work for me:

wscript.sleep 1000

Delay 10

Sub Delay( seconds )
    Dim wshShell, strCmd
    Set wshShell = CreateObject( "Wscript.Shell" )
    strCmd = "%COMSPEC% /C (PING -n " & ( seconds + 1 ) & " 127.0.0.1 >NUL 2>&1 || PING -n " & seconds & " ::1 >NUL 2>&1)"
    wshShell.Run strCmd, 0, 1
    Set wshShell = Nothing
End Sub

dim oshell 
set oshell = CreateObject("Wscript.Shell") 


obshell.run "%windir%\system32\rundll32.exe kernel32.dll Sleep 5000" 
like image 822
ladiesman1792 Avatar asked Jan 22 '15 10:01

ladiesman1792


2 Answers

The first statement, WScript.Sleep 1000, does work. Your error must be somewhere else.

Proof

Create a file test.vbs on your desktop:

WScript.Echo Time()
WScript.Sleep 2000
WScript.Echo Time()

Run as follows:

C:\Users\...\Desktop>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

11:31:34
11:31:36

Note the two second difference. (If this exact script produces a different outcome on your PC, please say so in the comments and accept my apology.)

like image 103
Heinzi Avatar answered Sep 21 '22 18:09

Heinzi


You cannot use the WScript object in VB script custom actions. The WScript object is supplied by the script environment when you run it in Windows Script Host, and is not in the MSI environment. That means there is no way to do a delay, so maybe you could describe the problem you're having that the delay might solve.

like image 22
PhilDW Avatar answered Sep 23 '22 18:09

PhilDW