如何延迟 VB 脚本?
How to delay in VB Script?
如何延迟 Vb 脚本?
以下代码对我不起作用:
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"
第一个语句 WScript.Sleep 1000
、 有效。你的错误一定是在别的地方。
证明
在您的桌面上创建文件 test.vbs:
WScript.Echo Time()
WScript.Sleep 2000
WScript.Echo Time()
运行如下:
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
注意两个秒的区别。 (如果此 exact 脚本在您的 PC 上产生不同的结果,请在评论中说明并接受我的道歉。)
您不能在 VB 脚本自定义操作中使用 WScript 对象。当您在 Windows 脚本宿主中 运行 时,WScript 对象由脚本环境提供,而不是在 MSI 环境中。这意味着没有办法延迟,所以也许你可以描述你遇到的延迟可能会解决的问题。
如何延迟 Vb 脚本? 以下代码对我不起作用:
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"
第一个语句 WScript.Sleep 1000
、 有效。你的错误一定是在别的地方。
证明
在您的桌面上创建文件 test.vbs:
WScript.Echo Time()
WScript.Sleep 2000
WScript.Echo Time()
运行如下:
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
注意两个秒的区别。 (如果此 exact 脚本在您的 PC 上产生不同的结果,请在评论中说明并接受我的道歉。)
您不能在 VB 脚本自定义操作中使用 WScript 对象。当您在 Windows 脚本宿主中 运行 时,WScript 对象由脚本环境提供,而不是在 MSI 环境中。这意味着没有办法延迟,所以也许你可以描述你遇到的延迟可能会解决的问题。