运行 命令后控件不返回原始 vbs 文件

control not returning to original vbs file after run command

我正在尝试调用另一个 vbs 文件。调用的文件执行。但是,控件不会返回到原始 vbs 文件。当我在任务管理器中看到 wscript 进程时,这个文件似乎是 运行ning。但我没有看到输出 - 运行 命令后的步骤。任何 help/suggestion 将不胜感激。

1.)vbs文件1(原vbs文件test3.vbs)

Set objShell = WScript.CreateObject ("WScript.shell")
strErrorCode  = objShell.run("cmd /K C:\temp\a\test2.vbs", 0, True)
msgbox "complete test3"
Set objShell = Nothing

2.) vbs 文件 2(称为 vbs 文件 - test2.vbs)

msgbox "in test2"
WScript.Sleep 10000
msgbox "complete - test2"

3.) 预期输出:

in test2
complete - test2
complete test3

4.) 实际:

in test2
complete - test2

objShell.run("cmd /K C:\temp\a\test2.vbs", 0, True) 由于 /K 开关而永远不会结束:

cmd /?
Starts a new instance of the Windows command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains

因此 cmd window 保持打开状态,但由于 intWindowStyle 参数而被隐藏:0 = 隐藏 window 并激活另一个 window,假设 Run 方法语法模式为 .Run(strCommand, [intWindowStyle], [bWaitOnReturn])

使用

strErrorCode  = objShell.run("cmd /C C:\temp\a\test2.vbs", 0, True)

strErrorCode  = objShell.run("wscript.exe C:\temp\a\test2.vbs", 0, True)

甚至

 strErrorCode  = objShell.run("C:\temp\a\test2.vbs", 0, True)