Write to Windows Registry on Windows shutdown

Pika
Pika used Ask the Experts™
on
Hello ;-)

I want to write something in the Windows Registry when the program terminitates on Windows shutdown. I tried OnFormDestroy and OnFormClose but they only seem to work when the program is terminated by itself (so a close button or something). I want the program to write some keys in the Windows Registry on Windows shutdown (so the program will be closed automaticly by Windows).
How can I do that?

Thanx in Advance!

Pika
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
hello Pika, you can get the WM_ENDSESSION or WM_QUERYENDSESSION message and then write to the registry or whatever you need to do, the WM_QUERYENDSESSION message is sent to ask if it is OK to exit windows, but you could use the
 WM_ENDSESSION, and then write to the registry.

procedure WMQUERYENDSESSION(var Msg: TMessage); message WM_QUERYENDSESSION;

procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;


I hope this is helpful, ask questions if you need more.

Author

Commented:
procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;

this line causes an error:

message WM_ENDSESSION;

do i have to put something in the 'uses' list?

the code that i need to use is:

begin
 WriteToRegistry(True);
end;

i've already declared the True so i don't need help with that ;-)

procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;
begin
 WriteToRegistry(True);
end;

doesn't work --> error: message WM_ENDSESSION;
I thought you have done windows messages from the Application before, since you haven't


  private
    { Private declarations }
    procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;



var
  MainForm: TMainForm;

implementation


procedure TForm1.WMENDSESSION(var Msg: TMessage);
begin
Msg.Result := 0;
WriteToRegistry(True);
end;

- - - - - - - - - - - - - - - - - -

you can get some additional info about the end of the session with the wParam and the LParam, look in the API help for WM_ENDSESSION

Author

Commented:
yep, it works ;-)
thx a lot!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial