[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What events are triggered during a 'logoff'

Posted on 2006-06-25
5
Medium Priority
?
684 Views
Last Modified: 2008-01-09
Hi

What events are triggered when a user logs off from windows 2000/xp etc?

I have tried a test using the events below, but none of them seem to get triggered.

Thanks
Pete

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
debugMSG ('formclose');
showmessage('formclose');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
debugMSG ('formdestroy');
showmessage('formdestroy');
end;

procedure TForm1.WMENDSESSION(var Msg: TMessage);
begin
debugMSG ('wmendsession');
showmessage('wmendsession');
end;
procedure TForm1.WMQUERYENDSESSION(var Msg: TMessage);
begin
debugMSG ('WMQUERYENDSESSION');
showmessage('WMQUERYENDSESSION');
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
debugMSG ('FormCloseQuery');
end;
0
Comment
Question by:PeteMulford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 1000 total points
ID: 16981790
Hi,

When user logs off you will receive WM_QUERYENDSESSION message. But I think you can not cought it while IDE is running (the reason might be that the IDE will receive the same message and terminate its process or debugger). To test it run the application outside the IDE.

the message should look like

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

procedure TForm1.OnLogOff(var Msg: TMessage);
begin
  ShowMessage('End Session');
  Msg.Result := 0; // This will stop the log off
end;
0
 
LVL 11

Assisted Solution

by:pcsentinel
pcsentinel earned 1000 total points
ID: 16982100
you do get the endsession

trap it by

type TForm1 = class(TForm)
*************
    procedure WndProc(var Msg: TMessage); override;
private
********
public
*******
end;

procedure TForm1.WndProc(var Msg: TMessage);
//traps incoming messages to check for close events
begin
if Msg.Msg=WM_QueryEndSession then //Send Disconnect And Close Event to Clients
      begin
         >>>>Dosomethinghere
        inherited WndProc(Msg);
      end
      else
        inherited WndProc(Msg);
end;
0
 

Author Comment

by:PeteMulford
ID: 16982108
Hi

Thank you,  I tried your suggestion with a small demo project, but that event doesnt seem to get triggered either :( I'm testing it on a win 2000 client pc connected to a windows 2000 server based network. The pc I'm testing it on does not have the IDE installed. I also noticed that it 'logs off' very quickly, not sure if thats a network setting, but shall investigate.

My code is:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    procedure OnLogOff(var Msg : TMessage); message WM_QUERYENDSESSION;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure debugMSG(msg:string);
const
  FileName = 'c:\closeEvents.txt';
var
  F: TextFile;
begin
  AssignFile(f,FileName);
 if FileExists(FileName) then Append(f)
 else
    Rewrite(f);
try  writeln(f,DateTimeToStr(Now)+':'+msg);
except windows.Beep(200,50);
end;
//  ShowMessage(DateTimeToStr(Now));
  CloseFile(f);
end;

procedure TForm1.OnLogOff(var Msg: TMessage);
begin
  debugMSG ('OnLogOff');
  ShowMessage('OnLogOff');
  Msg.Result := 0; // This will stop the log off
end;

end.
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16982146
Tested on XP. it created the 'c:\closeEvents.txt' file with following content and did not log off

26/06/2006 1:40:32 PM:OnLogOff
0
 

Author Comment

by:PeteMulford
ID: 16982874
Many thanks to both of you. Both solutions actually work, seemingly equally well, it was another application causing my problems by forcing a loggoff.

Pete

 
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question