【问题标题】:control not returning to original vbs file after run command运行命令后控制不返回原始 vbs 文件
【发布时间】:2019-05-12 23:57:01
【问题描述】:

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

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

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    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 窗口保持打开但由于intWindowStyle 参数而被隐藏:0 = 隐藏窗口并激活另一个窗口,假设Run 方法语法模式为@987654328 @

    使用任一

    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)
    

    【讨论】:

      猜你喜欢
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多