How I can detect when a system is going to reboot or shutdown? I have tried something like:

invoke GetMessage, ADDR MESG, NULL, 0, 0
cmp MESG.message, WM_ENDSESION
je showbox
invoke DispatchMessage, ...
jmp start

invoke messagebox, .....

I have tried with WM_QUERYENDSESSION too but hasn't worked, I don't see the box with the message. Where is the problem?
Posted on 2002-10-16 17:57:30 by wildark

I'm not sure exactly, but you might want to check if the hWnd of the Message function is HWND_BROADCAST (message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows).

I remember reading that a message specified in this way is broadcast to applications before the system terminates to allow them to do any cleaning up, saving of data, etc. You could also check out if BroadcastSystemMessage is used.

Hope this helps,
Posted on 2002-10-16 19:32:09 by Kayaker
WM_ENDSESSION and WM_QUERYENDSESSION are sent to windows; they are not sent to thread queues. (I think)

Try creating a window.
Posted on 2002-10-17 01:38:06 by iblis
I have tried to create a window and it has not work... any idea? :mad:
Posted on 2002-10-17 09:10:11 by wildark

there's a not elegant (and also stupid ) way that maybe could work.
Before shutdown, the system should close all opened applications. You can try to check when your application comes destroyed...

Posted on 2002-10-17 09:39:48 by ZaiRoN
My first guess is that during Windows shutdown, it will not allow other windows
to be created (makes since at least). Or, on the off chance that it *did* allow it,
it would almost immediately recieve the message to close down itself.

you will need to return a 0 from WM_QUERYENDSESSION in order to stop it from
ending the session. Then you can clean up and do what you need to do and
close Windows down yourself. Although I do not see the point as clean up code
can be put into WM_CLOSE as well...
Posted on 2002-10-17 11:18:32 by Graebel
Hook NtShutdownSystem()
Posted on 2002-10-21 04:37:45 by Rama