Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-07

shutting down win9x

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lee, John

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!

Reply by email

Kanzelsberger Pavel

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

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

regards, Pavel Kanzelsberger

Earlier message 13 lines
-----Original Message----- From: Lee, John Sent: Wednesday, July 11, 2001 9:15 PM To: '' Subject: [fpc-pascal]shutting down win9x 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!

Reply by email

Thomas Schatzl
to Kanzelsberger Pavel

----- Original Message -----

Show quoted text 9 lines
From: Kanzelsberger Pavel To: '' 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:

const
    done_my_stuff : Boolean = false;
function WindowHandler(wnd : HWnd; msg : DWord; wParam, lParam : Longint) :
Longbool;
begin
    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;
        end;
        WM_USER : begin
            // you could as well spawn another process (call program) here
            Do_Your_Stuff_here;
            done_my_stuff := true;
            if ((lParam and ENDSESSION_LOGOFF)  0) then
                lParam := EWX_LOGOFF
            else
                lParam := EWX_SHUTDOWN;
            ExitWindowsEx(lParam, 0); // abort windows ourselves
            result := true;
        end;
        else begin
            result := DefWindowProc(wnd, msg, wParam, lParam);
        end;
    end;
end;

*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.

Show quoted text 7 lines
[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 that.

Regards,
Thomas

Reply by email

Andrew Higgs
to Lee, John: Is it possible automatically to run a fpc (or other) program when one clicks on the…

Hi Lee,

Is it necessary for shutdown to call your program or can your program call shutdown. ExitWindowsEx should do the trick if running your app to shutdown windows is ok. This is in the windows unit. I don't have examples as I work in linux mostly.

HTH.

kind regards Andrew Higgs > "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!

Reply by email