How to abort shutdown in Windows (XP|Vista) programatically?

折月煮酒 提交于 2019-11-27 22:25:18
Piskvor

From 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.

So, my application's WindowProc now processes the WM_QUERYENDSESSION message and returns 0.

Didn't expect it to be this simple; as a bonus, it also works on Windows 2000.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!