在 VBScript 中,该WScript.Shell.Run
方法具有三个参数,其中第三个参数是一个布尔值,用于指定程序是否应该等待新生成的进程完成后再继续。
我无法让这种行为正常工作mstsc.exe
(Windows 中的远程桌面连接程序)。
如果我将以下文件另存为test.vbs
并使用 执行它cscript test.vbs
,它会按预期工作。
Set obj = CreateObject("WScript.Shell")
Call obj.Run("notepad.exe", 1, true)
MsgBox "You just closed notepad."
Call obj.Run("mstsc.exe", 1, true)
MsgBox "Remote desktop just closed."
但是,如果我尝试从 HTA 文件执行相同的代码,它就不能正常工作——相反,运行后的消息框会mstsc.exe
立即出现,而不是等待。
<html>
<head>
<script language="VBScript">
Sub RunProgram
Set obj = CreateObject("WScript.Shell")
Call obj.Run("notepad.exe", 1, true)
MsgBox "You just closed notepad."
Call obj.Run("mstsc.exe", 1, true)
MsgBox "Remote desktop is still open!"
End Sub
</script>
</head>
</body>
<body onload=RunProgram>
</html>
知道为什么会发生这种情况以及如何解决吗?
编辑:我已经在 Windows 10 和 7 上对此进行了测试。