What is the win32 function to check whether a shutdown is initiated or not?
EDIT: I need to check that inside a windows service (COM). How to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no actual Win32 function to check for that.
Instead Windows sends the
WM_QUERYENDSESSIONmessage to every application when a shutdown is initiated.You can respond to that message and for example cancel the shutdown. (Although you shouldn’t do that unless it is absolutely necessary)
Before the actual shutdown the
WM_ENDSESSIONmessage is sent.You should do any of your cleanup only after this message, because it is not guaranteed that the system actually shuts down after
WM_QUERYENDSESSION.EDIT:
If you want to listen for these messages from a Service you have to put some more work into it.
Services normally don’t have windows, so you cannot simply hook into an existing window message queue. Instead you have to create a dummy window, which is meant only to processes messages and use it to handle the messages above.
See the MSDN documentation for more information about message-only windows.