Execute code on computer shutdown

Hi,

how can I make program to execute code when I will turn my PC off or hybernate him?
If in MS Windows, process WM_QUERYENDSESSION and WM_ENDSESSION. See http://msdn.microsoft.com/en-us/library/aa376890(VS.85).aspx for more details. It seems that a regular application cannot know whether the session end is due to a log off or a shutdown, though.

Windows Services, on the other hand, can distinguish between the two.
Also if you're not dead set on using C++ to accomplish your task then:

Start -> Run -> mmc -> File -> Add\Remove Snap-in -> Group Policy Object Editor (Local) -> Computer Configuration -> "Scripts (Startup/Shutdown)" -> Shutdown

That would be the more traditional way of doing it, always use the right tool for the job
Last edited on
Topic archived. No new replies allowed.