2

在 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 上对此进行了测试。

4

1 回答 1

4

使用 64 位版本的 mstsc。c:\windows\sysnative\mstsc.exe Sysnative允许 32 位程序访问System32目录。尝试访问的 32 位程序C:\windows\system32被重定向到c:\windows\syswow64.

从我的第一条评论开始。

我在 Windows 10 上得到了同样的结果。我怀疑这与 HTA 设置为以 32 位运行有关,但即使将 mstsc 更改为 32 位版本也没有任何区别

于 2016-07-23T00:32:52.487 回答