如何在执行过程中保持 VBScript 命令窗口打开 [英] How to keep the VBScript command window open during execution
问题描述
当我执行 VBScript 时,它创建的命令窗口在用户有机会阅读输出之前迅速关闭.如何在不修改 Windows 注册表的情况下让窗口保持打开状态?
When I execute a VBScript, the command window that it creates closes quickly before the user gets a chance to read the output. How can I get the window to stay open without modifying windows registry?
这是代码:
Set objShell = WScript.CreateObject("WScript.shell")
objShell.Run "SyncToyCmd.exe -R", 1, True
推荐答案
您可以通过 cmd.exe
命令解释器发送您的执行命令,以及一个暂停命令,该命令会给用户一个 <代码>按任意键继续... 提示关闭窗口.
You can send your execution command through the cmd.exe
command interpreter, along with a pause command which will give the user a Press any key to continue . . .
prompt to close the window.
objShell.run "%comspec% /c ""SyncToyCmd.exe -R & pause""", 1, True
或者为了让窗口保持活动状态,使用 /k
标志而不是 /c
:
Or to keep the window alive, use the /k
flag instead of /c
:
objShell.run "%comspec% /k SyncToyCmd.exe -R", 1, True
但请注意,在手动关闭此 cmd 窗口之前,您的 VBScript 不会继续(或终止).
But beware, your VBScript will not continue (or terminate) until this cmd window is manually closed.
%comspec%
环境变量指的是根据您的操作系统打开命令解释器的正确命令.例如,在我的 XP 机器上,%comspec%
等于 C:\WINDOWS\system32\cmd.exe
.
The %comspec%
environment variable refers to the correct command to open the command interpreter as per your operating system. On my XP machine, for instance, %comspec%
is equal to C:\WINDOWS\system32\cmd.exe
.
请参阅此处的 cmd.exe
文档:http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
See cmd.exe
documentation here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
有关使用 &
与 &&
命令分隔符的更多信息 此处.
More info on the use of the &
versus the &&
command separators here.
这篇关于如何在执行过程中保持 VBScript 命令窗口打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!