Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Hook to avoid shutdown

0 views
Skip to first unread message

Achmed

unread,
May 23, 2007, 12:17:15 PM5/23/07
to
Is it possible to override the shutdown of a hooked application. The user
may decide to shutdown via the system or the File menu and I'd like to
override that and perform the shutdown after some delay.

Thanks

Achmed


Kellie Fitton

unread,
May 23, 2007, 12:29:35 PM5/23/07
to


Hi,

Try to create a hook into the windows message WM_QUERRYENDSESSION
so you can have a bit more head start, otherwise the system could
assumes an unresponsive process is dead, and takes actions against it.
remember every application gets the message WM_QUERYENDSESSION,
and in your reply you can say "yes" or "no" but your answer is only
one vote, the first application to respond to this message stops the
polling by windows. Also, use the API SetProcessShutdownParameters()
to set the shutdown parameters for the current calling process.

You need to use a system-wide hook, for example, WH_CALLWNDPROC to
monitor messages being sent, and WH_CALLWNDPROCRET to monitor the
messages handlers returning, and a hook procedure in a .DLL file.

Try to use the following APIs:

SetWindowsHookEx()
CallNextHookEx()
UnhookWindowsHookEx()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setprocessshutdownparameters.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/wm_queryendsession.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/callnexthookex.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/unhookwindowshookex.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/abouthooks.asp

Kellie.


Gary Chanson

unread,
May 23, 2007, 5:21:14 PM5/23/07
to

"Achmed" <Bac...@sadat.co.jd> wrote in message
news:eHZjw1Un...@TK2MSFTNGP02.phx.gbl...

> Is it possible to override the shutdown of a hooked application. The user
> may decide to shutdown via the system or the File menu and I'd like to
> override that and perform the shutdown after some delay.

It should be easy to hook WM_CLOSE and WM_SYSCOMMAND(SC_CLOSE), but
hooking the close entry on the file menu could be a bit tricky. If you
examine the messages initiated by that command, you may find the it's easy
enough to hook WM_COMMAND with the appropriate parameters.

--

- Gary Chanson (Windows SDK MVP)
- Abolish Public Schools


0 new messages