带 windows-scripting-host 的关闭挂钩
此链接讨论了如何使用 VB 实现关闭挂钩。现在我的问题是,可以使用 Windows 脚本主机/Windows 脚本主机来完成类似的事情吗?
我非常感谢您的意见;也许包括一些代码片段。
This link discusses how a shutdown hook can be implemented using VB. Now my question is, can something like that be done using Windows Script Host/windows scripting host?
I would very much appreciate your input; maybe include some code snippets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定其他脚本语言(例如 PowerShell 或 Perl),但在 VBScript/JScript 中似乎没有办法做到这一点。
首先,Windows Script Host 不提供对 Windows API 的访问,因此您无法拦截
WM_ENDSESSION
和WM_QUERYENDSESSION
Windows 消息(如您提到的文章中所建议的)来自 VBScript/JScript。不过,有 WMI
Win32_ComputerShutdownEvent
事件,当计算机关闭时发生这种情况,但是 您只能从已删除的计算机接收此事件。当本地计算机关闭时,脚本会在事件传递之前终止。Not sure about other scripting languages such as PowerShell or Perl, but in VBScript/JScript there doesn't seem a way to do this.
First of all, Windows Script Host doesn't provide access to Windows API so you can't intercept the
WM_ENDSESSION
andWM_QUERYENDSESSION
Windows messages (as suggested in the article you mentioned) from VBScript/JScript.There's the WMI
Win32_ComputerShutdownEvent
event though, which occurs when a computer shuts down, but you can only receive this event from remove computers. When the local computer shuts down, the script is terminated before the event is delivered.