如何以编程方式中止 Windows Vista 和 7 中的关机?
在此链接上的第二个示例(在示例部分中)中,有有关使用 WM_QUERYENDSESSION 中止关闭的说明。它还指出这不适用于 XP 之后的 Windows 版本。这与此处的另一个问题给出的建议相冲突堆栈溢出。正确答案是什么?我没有电脑,所以无法测试。
In the second example (in the section examples) on this link, there is a description on using WM_QUERYENDSESSION to abort a shutdown. It also states that this does not work on versions of windows later than XP. This is conflicting with the advice given on another question here at stackoverflow. What is the correct answer? I do not have a computer with either so I am unable to test.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
某些应用程序的 WM_QUERYENDSESSION 处理错误(未传递给 DefWindowProc,即使它们不打算阻止关闭,它们也错误地返回 0),因此 MS 在 Vista 中更改了它,您现在需要调用 ShutdownBlockReasonCreate()
@Konamiman:shutdown.exe -a 将中止“计划的”关闭是的,但不是由调用 ExitWindowsEx() 的人“正常”关闭
Some applications got the WM_QUERYENDSESSION handling wrong (Not passing to DefWindowProc, they incorrectly returned 0 even though they did not intend to block shutdown) and so MS changed it with Vista, you now need to call ShutdownBlockReasonCreate()
@Konamiman: shutdown.exe -a will abort a "scheduled" shutdown yes, but not a "normal" shutdown by someone calling ExitWindowsEx()
如果其他任何操作失败,请记住在命令行中它是
shutdown.exe -a
;也许您可以使用 Process 类来调用它。编辑。当提到 Process 类时,我很高兴地认为问题是关于 .NET 编程的,现在我看到问题和标签中都没有提到 .NET。无论如何,我相信也有方法可以从其他编程环境运行可执行文件。
If anything else fails, remember that from command line it is
shutdown.exe -a
; maybe you could invoke this using the Process class.EDIT. When mentioning the Process class I happily assumed that the question was about .NET programming, now I see that .NET is not mentioned neither in the question nor in the tags. Anyway I believe that there are ways to run executables from other programming environments as well.