如何以编程方式在 Windows (XP|Vista) 中中止关机?
我希望能够 1. 检测(如果需要,2. 中止)我的应用程序中的操作系统关闭,最好使用 Windows API。
我知道可以使用命令 shutdown -a
手动中止关闭,在最坏的情况下,我可以通过 ShellExecute 执行此操作,但我想知道是否有更好的方法来以编程方式防止关闭。
也许以编程方式通知操作系统即将关闭就足够了 - 如何做到这一点?
I want to be able to 1. detect (and, if needed 2. abort) OS shutdown from my application, preferably by using the Windows API.
I know that it is possible to abort shutdown manually using the command shutdown -a
In the worst case, I could ShellExecute this, but I was wondering if there was a better way to prevent the shutdown programatically.
Maybe it would be enough to be notified programatically that the OS is about to shut down - how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 MSDN:
因此,我的应用程序的 WindowProc 现在处理
WM_QUERYENDSESSION
消息并返回0
。没想到这么简单; 另外,它还可以在 Windows 2000 上运行。
From MSDN:
So, my application's WindowProc now processes the
WM_QUERYENDSESSION
message and returns0
.Didn't expect it to be this simple; as a bonus, it also works on Windows 2000.
关于“简单地”返回 0 来阻止关闭,如果您想以正确的方式执行此操作,则事情并不那么简单。 尤其是在 Vista 上。 例如,另请阅读 http://msdn.microsoft。 com/en-us/library/ms700677(VS.85).aspx
In regards to 'simply' returning 0 to block a shutdown, it isn't as simple as that if you want to do it in the proper way. Especially on Vista. For example please also read http://msdn.microsoft.com/en-us/library/ms700677(VS.85).aspx