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.)