Differentiate Shutdown or Reboot from WM_QUERYENDSESSION Message

C

Craig Peacock

Is it possible to determine from a service if a computer is shutting
down or rebooting, or if it is suspending or hibernating?


I currently have an NT service which can perform some lengthy
background tasks. If a user tries to shutdown the computer I want to
hold up the process until the background task finishes.

At present I get the WM_QUERYENDSESSION and WM_POWERBROADCAST messages
which I fail and display a dialog to the user that the background task
is running and the computer will reboot/shutdown or suspend/hibernate
as soon as the process finishes.

I can determine from the WM_QUERYENDSESSION if the user is logging out
or shutting down/rebooting, but I can differentiate between the
shutdown and reboot. Likewise with the WM_POWERBROADCAST, I can't
differentiate if the computer is hibernating or suspending. As a
consequence it makes it hard to reschedule the operation later.

If I simply hold the notification message, windows will start shutting
down my app in 30 seconds. I need to hold it off for a period of
minutes.

Regards,

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top