在VBScript中,WScript.Shell.Run
方法有three arguments,其中第三个是布尔值,指定程序是否应等待新生成的进程在继续之前完成。bWaitOnReturn从HTA运行时对mstsc.exe没有影响
我无法使此行为与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
不能重现做。第二个消息框仅在两种情况下关闭RDP连接后出现。 –
@AnsgarWiechers你正在使用什么操作系统?我应该提到我在Windows 10上遇到过这个问题......(尽管已经在几台PC上尝试过了)。 –
我在Windows 10上得到了同样的结果。我怀疑这是因为HTA被设置为32位运行,但即使将mstsc更改为32位版本也没有区别。 – 2016-07-23 00:26:30