如何让 HTA 自行重启?
我有一个 HTML 应用程序,用于构建信息亭环境。在每个会话结束时(当用户单击“注销”或超时后),我希望 HTA 自行关闭并重新启动*。我想知道如何使用 VBScript 以编程方式实现这一目标。
该过程应该像这样
- 用户单击“注销”或者如果 5 分钟内没有输入
- 删除临时 Internet 文件
- 关闭 HTA
- 重新打开 HTA
这是我遇到问题的重新打开部分。
我确实考虑过的一件事是;在关闭应用程序之前,设置一次性计划任务以再次运行 HTA。不过,我不认为这是一个非常优雅的解决方案:(
感谢你们的帮助!
干杯
Iain
。*我希望 HTA 自行重新启动的原因是,在长时间使用后,奇怪的事情开始发生,我认为与mshta.exe 或 IE 引擎中的错误我的 HTA 非常依赖于动态创建的 IFRAME,并且由于某种原因,HTA 在关闭它们后无法正确清理它们。奇怪的例子是;我生成了一个新的 IFRAME,当我询问 DOM 时,一切看起来都像它应该的那样,但浏览器呈现的是之前聚焦的 IFRAME 中的内容。
I have an HTML Application that I am using to build a kiosk environment. At the end of every session (when the user clicks "Logout" or after a timeout) I want the HTA to close itself and restart*. I was wondering how I would go about achieving this programatically with VBScript.
The process should go something like this
- User clicks "logout" or if there has been no input for 5 minutes
- Delete temporary internet files
- Close HTA
- Reopen HTA
It's the reopening part I'm having trouble with.
One thing I did consider is; before closing the application, set a once-only scheduled task to run the HTA again. I don't think this is a very elegant solution though :(
Thanks for your help guys!
Cheers
Iain
.* The reason I want the HTA to restart itself is that after extended use, strange things start to happen that I think are related to bugs in mshta.exe or the IE engine. My HTA relys quite heavily on dynamically created IFRAMEs and for some reason the HTA doesn't clean them up properly once they're closed. It's kind of hard to explain the bug in detail but an example of the weirdness is; I spawn a new IFRAME and when I interrogate the DOM everything looks like it should, but what the browser renders is whatever was in the previously focussed IFRAME.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注销或超时时,HTA 运行重新启动脚本,然后退出。重新启动脚本等待 MSHTA 进程消失,然后重新启动它并自行退出。
这可以通过使用 WMI 扫描正在运行的进程并查找命令行参数包含 HTA 名称的 MSHTA.EXE 实例来完成。
这是一个演示这一点的小例子。
这是一个准系统 HTA,将其另存为 RestartTest.hta:
这是重新启动脚本,另存为 RestartHTA.vbs:
您可以运行任一脚本来启动循环,然后只需使用 X 按钮关闭 HTA 即可将其中断。请注意,我显式地使用 CScript 运行重新启动脚本。这只是为了演示目的而显示它的控制台输出(并且因为出于某种原因我无法将 CScript 设置为我的计算机上的默认值)。
When logging off or timing out, the HTA runs a restart script, then exits. The restart script waits for the MSHTA process to go away, then restarts it and exits itself.
This can be done by using WMI to scan running processes and look for an instance of MSHTA.EXE who's command line parameter contains the name of the HTA.
Here is a little example that demonstrates this.
This is a barebones HTA, save it as RestartTest.hta:
This is the restart script, save as RestartHTA.vbs:
You can run either one to start the cycle, then just close the HTA with it's X button to break it. Note that I run the restart script with CScript explicitly. This is just to show it's console output for demo purposes (and because I have trouble setting and keeping CScript as the default on my machine for some reason).
看一下下面的代码:
Take a look at the below code: