vbscript - 运行命令后控制不返回原始 vbs 文件
问题描述
我正在尝试从另一个调用 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
解决方案
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,假设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)
推荐阅读
- mysql - sql根据跨多个表的值更新表列
- firebase - 参数类型'流
?不能分配给参数类型'Stream >? - python - 从字典调用时的函数输出格式
- java - 带有发布请求的 THYMELEAF:执行处理器“org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor”时出错
- sql - 使用 BigQuery 时出现错误消息:无法识别的名称:HTN_Global
- google-sheets - Google 表格错误:url 内容中的资源超出了最大大小 importhtml
- android - JC中的弯曲文本字段?
- java - 使线程在等待其他东西时可用
- wordpress - 让子 CSS 文件在 DIVI Theme Wordpress 中最后加载
- bash - 如何在 Ubuntu 上使用 bash 创建 GitHub 存储库机密/加密它?