Stop Windows shutdown from a service
Posted on 2003-03-23
Hi all experts,
I have a C application that runs as service in Windows XP. I want to be able to warn the user before the computer is being shut down and halt the shutdown if the user chooses to. FYI, the program was developed using Visual C++ using the Win32 Console Application option. I just added some codes found on the Net to make it a service and it's not an ATL COM service or anything fancy.
I know 'normal' program can use message maps to catch the WM_QUERYENDSESSION and return a false answer (not really sure though) to prevent shutdown. How can I do that with a service because services due to their nature are supposed to run silently in the background. The best I can do now (and it's really lame) is pop up a message box using the MB_SERVICE_NOTIFICATION by putting some codes under the ServiceHandler SERVICE_CONTROL_SHUTDOWN case but this hardly suffice as I can't prevent the shutdown and there's no option for the user to click Yes or No.
Is there anyway I can do this at all? Is the WM_QUERYENDSESSION message sent to services at all? Please provide source codes if possible. Points will be increased if I feel the accepted answer is thorough and, of course, solves my problem as soon as possible.