Perform operations on Windows shutdown

Giganews Newsgroups
Subject: Perform operations on Windows shutdown
Posted by:  Adrien Reboisson (nothi…
Date: 31 Aug 2006


My software needs to execute a backup application when the user
shutdown the computer. I thought first to catch WM_ENDSESSION
and WM_QUERYENDSESSION messages in order to run the process but
here is the problem :
- If I abort the shutdown operation when receiving the
WM_QUERYENDSESSION message I can run my process safely, but
I cannot reinitiate the operation when the process is finished
since there is not enough informations in the message to know
what was the original operations initiated by the user.
- If I just detect the WM_ENDSESSION message and run the process,
it could be killed by Windows if it does not end quickly.

I already used Windows Update, and when the system must be
updated, patches are something applied when the computer is
turned off.
A nice blue screen is displayed and it's written (sorry for
my translation, the original message is in French !) "Please
wait while your computer is updated. Installing update, 1 of 5".
When all is finished, the requested action is done (reboot,
shutdown, etc.).

I find the way used by WU rather nice and elegant.
Is there a set of API which can be used to run some programs
and perform some operations as WU do ? More generaly, is there
a "safe" way to execute programs when the PC is rebooted/
turned off ?

Best regards,