[fpc-pascal]shutting down win9x

Thomas Schatzl tom_at_work at yline.com
Thu Jul 12 11:03:24 CEST 2001

----- Original Message -----
>From: Kanzelsberger Pavel
>To: 'fpc-pascal at deadlock.et.tudelft.nl'
>Sent: Thursday, July 12, 2001 10:09 AM
>Subject: RE: [fpc-pascal]shutting down win9x
> [Pavel wrote]
>When Windows shutsdown by ExitWindows() or by ExitWindowsEx() it's
>send CTRL_SHUTDOWN_EVENT messages to processes... as far I
>remember, you should refer to Win32 SDK

CTRL_SHUTDOWN_EVENT is sent to console processes only. Imho it's better to
create an invisible GUI process and monitor WM_QUERYENDSESSION because you
don't have a dos box window hanging around then.

>I think you should write some small process monitoring this message and
>then quickly execute anything you want...

The message handler could look like the following:

    done_my_stuff : Boolean = false;

function WindowHandler(wnd : HWnd; msg : DWord; wParam, lParam : Longint) :
    case (msg) of
        WM_QUERYENDSESSION : begin
            // only execute user proc if not already done
            if (not done_my_stuff) then
                PostMessage(wnd, WM_USER, 0, lParam);
            // tell windows to 'abort' logoff if program
            // hasn't executed yet
            result := done_my_stuff;
        WM_USER : begin
            // you could as well spawn another process (call program) here
            done_my_stuff := true;
            if ((lParam and ENDSESSION_LOGOFF) <> 0) then
                lParam := EWX_LOGOFF
                lParam := EWX_SHUTDOWN;
            ExitWindowsEx(lParam, 0); // abort windows ourselves
            result := true;
        else begin
            result := DefWindowProc(wnd, msg, wParam, lParam);

*Should work* (didn't verify). This doesn't work with W2k/NT - you need to
get permissions whether you're allowed to shutdown the computer first before
calling ExitWindowsEx with EWX_SHUTDOWN.
Refer to the SDK help how to do that, there's an example how to do that.

> [Lee John wrote]
>Is it possible automatically to run a fpc (or other) program when one
>clicks on the Start/Shut Down menu on the
>win9x desktop, before windoze start its shutdown sequence? How?
>Does windoze look somewhere for a bat file called shutdown.bat ot whatever?
>Where? TIA for any info - think I should probably know this!

No. But there are already lots of tools available on the 'net which allow


More information about the fpc-pascal mailing list