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"
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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With