gpt4 book ai didi

winapi - 如何以编程方式在 Windows (XP|Vista) 中中止关机?

转载 作者:行者123 更新时间:2023-12-02 14:37:49 25 4
gpt4 key购买 nike

我希望能够 1. 检测(如果需要,2. 中止)我的应用程序中的操作系统关闭,最好使用 Windows API。

我知道可以使用命令 shutdown -a 手动中止关闭 在最坏的情况下,我可以通过 ShellExecute 执行此操作,但我想知道是否有更好的方法来防止关闭以编程方式。

也许以编程方式通知操作系统即将关闭就足够了 - 如何执行此操作?

最佳答案

来自MSDN :

The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.

因此,我的应用程序的 WindowProc 现在处理 WM_QUERYENDSESSION 消息并返回 0

没想到这么简单;另外,它还可以在 Windows 2000 上运行。

关于winapi - 如何以编程方式在 Windows (XP|Vista) 中中止关机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/589986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com