从HTA运行时,bWaitOnReturn对mstsc.exe没有影响

时间:2016-07-22 22:51:56

标签: windows vbscript hta wsh mstsc

在VBScript中,WScript.Shell.Run方法有three arguments,其中第三个是布尔值,指定程序是否应该在继续之前等待新生成的进程完成。

我无法使用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上对此进行了测试。

1 个答案:

答案 0 :(得分:4)

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

从我的第一条评论开始。

我在Windows 10上也是这样。我怀疑它是将HTA设置为32位运行,但即使将mstsc更改为32位版本也没有区别