How to detect a system shutdown?
-
Is there a way to query windows to determine if a system shutdown is imminent? I have a user interface application which provides the option to execute an upgrader application. This upgrader application deletes some system files and then transfers new system files in place. The problem is that due to driver install (upgrade files are stored on a pcmcia card and windows asks to shutdown after the drivers are loaded sometimes), windows will sometimes send a messagebox asking for the unit to be restarted, which is very bad if the user selects ok when systems files have been deleted and not replaced yet. I've already put a handler function for the WM_QUERYENDSESSION message in the upgrader app (which works fine), but I still need to trap the condition in which the WM_QUERYENDSESSION message is sent before the upgrader application starts (in which case, the application missed this message). If I can find out if the shutdown is imminent, I can prevent the file transfer. Thanks, Himanshu
-
Is there a way to query windows to determine if a system shutdown is imminent? I have a user interface application which provides the option to execute an upgrader application. This upgrader application deletes some system files and then transfers new system files in place. The problem is that due to driver install (upgrade files are stored on a pcmcia card and windows asks to shutdown after the drivers are loaded sometimes), windows will sometimes send a messagebox asking for the unit to be restarted, which is very bad if the user selects ok when systems files have been deleted and not replaced yet. I've already put a handler function for the WM_QUERYENDSESSION message in the upgrader app (which works fine), but I still need to trap the condition in which the WM_QUERYENDSESSION message is sent before the upgrader application starts (in which case, the application missed this message). If I can find out if the shutdown is imminent, I can prevent the file transfer. Thanks, Himanshu
If any application returns zero for the WM_QUERYENDSESSION message the session will not be ended. To determine if the system is shutting down , Handle WM_ENDSESSION message and a non zero value for "lParam" says the system is shutting down.
There is no spoon. suhredayan -
If any application returns zero for the WM_QUERYENDSESSION message the session will not be ended. To determine if the system is shutting down , Handle WM_ENDSESSION message and a non zero value for "lParam" says the system is shutting down.
There is no spoon. suhredayanThanks for the suggestion, but I don't think that will be sufficient for my case. I need to know before the upgrader app gets WM_ENDSESSION. The reason is that the the message could come at some finite time after I have started, and if the timing is right, then I could be somewhere in between deleting and replacing the system files (The upgrader actually updates a remote module that takes a total of ~40 minutes, so it wouldn't be essy closeout the processing in OnEndSession). I would like to use some sort of API fcn that I could call before I start the transfer, so that I know I can guarantee that windows is not shutting down before the upgrade starts. It looks like there might not be one available. I guess I'll try to use another application to capture the QueryEndSession and then have the information available to the Upgrader at startup. Thanks, Himanshu
-
Thanks for the suggestion, but I don't think that will be sufficient for my case. I need to know before the upgrader app gets WM_ENDSESSION. The reason is that the the message could come at some finite time after I have started, and if the timing is right, then I could be somewhere in between deleting and replacing the system files (The upgrader actually updates a remote module that takes a total of ~40 minutes, so it wouldn't be essy closeout the processing in OnEndSession). I would like to use some sort of API fcn that I could call before I start the transfer, so that I know I can guarantee that windows is not shutting down before the upgrade starts. It looks like there might not be one available. I guess I'll try to use another application to capture the QueryEndSession and then have the information available to the Upgrader at startup. Thanks, Himanshu
heman154 wrote: I need to know before the upgrader app gets WM_ENDSESSION. The
WM_ENDSESSION
message is sent only if all applications respond to theWM_QUERYENDSESSION
message with a non-zero value. So, as long as you are handling theWM_QUERYENDSESSION
message, you're fine.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow