View Full Version : Windows shut down notification API?
dELTA
November 16th, 2004, 08:28
I'm almost certain that I have seen some Windows API that can be used to register a callback to be called just before Windows is about to shut down, sorta like IoRegisterShutdownNotification, but for ring 3 apps. As usual though, once you really need it, it's completely impossible to find again...
My problem is that the normal Windows quit message that is sent to windowed applications during Windows shutdown for some reason fails at seemingly random occasions for my application, so that the application cleanup and shutdown code isn't executed, and the program gets a "Program XXX isn't responding" warning to the user instead. Hence, I thought that such a registered callback function would hopefully be a little more robust.
If anyone has any clues about such a function, or any other good solution for that matter, please let me know.
Neitsa
November 16th, 2004, 09:18
Hello Delta,
As far as I know there's only some functions for shutting down windows, and, having browse them, none offer a callback function.
see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/system_shutdown_functions.asp
There's only two messages wich are sent to all programs:
WM_ENDSESSION
WM_QUERYENDSESSION
see :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/system_shutdown_messages.asp
you can also force a shutdown (nothing displayed, all programs are shutted down, even if they are doing some job) while calling ExitWindowsEx with the EXW_FORCE flag.
Hope it could help.
Regards, Neitsa.
bilbo
November 16th, 2004, 12:24
A callback could be in effect called, but only with Console Processes (and that is not supposed your case, dELTA).
You register it with
BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Quote:
The handler functions also handle signals generated by the system when the user closes the console, logs off, or shuts down the system. |
Just a marginal consideration. Regards, bilbo
Silver
November 16th, 2004, 13:56
As neitsa says, I've had success with WM_QUERYENDSESSION before. Alternatively, you might have some luck hooking this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/wlxshutdown.asp
dELTA
November 16th, 2004, 16:48
Thanks for the info guys, then I know what I have to work with.

SL0rd
November 17th, 2004, 12:05
Hi Delta, I have an idea:
Inject code in the windows kernel, so its send a personalized message to all the applications, you write a callback to this message and...what about it!
Neitsa
November 17th, 2004, 12:28
Quote:
Inject code in the windows kernel, so its send a personalized message to all the applications, you write a callback to this message and...what about it!
|
Errrr, sounds a little bit difficult....but it worth the try !
SL0rd
November 17th, 2004, 12:56
Hey Im a beginner, and its was just an idea...
dELTA
November 17th, 2004, 17:56
Hehe, yeah, I'm sure the users would appreciate me modifying their kernel to get around a quirk in my program, not to mention having their computer BSOD (or at least my program stop working, if the patcher is a bit more clever) when they run Windows Update the next time.

Shooting mosquitos with cruise missiles usually gets expensive in the end.

Powered by vBulletin® Version 4.2.2 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.