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

x
?
Solved

Event-handler for a service application

Posted on 2002-07-24
3
Medium Priority
?
265 Views
Last Modified: 2010-04-04
How to write an event-handler for a service application. Event = User Logoff and System Shutdown.

I want my service application to do something when a user logoff or shutdown the system.
0
Comment
Question by:mappemuppe
[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
3 Comments
 
LVL 2

Expert Comment

by:mullet_attack
ID: 7175890
use this api function

SetConsoleCtrlHandler
 
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 2000 total points
ID: 7175997
this is the best i can do...

I expected to be able to differentiate between logoff and shutdown, but that is not the case. For both events the parameter passed in the HandlerEvent is CTRL_CLOSE_EVENT.
Hope it's close enuff for you purposes :-)



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

type
  TATest = class(TService)
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceShutdown(Sender: TService);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

function HandlerEvent(eType : DWORD):boolean;

var
  ATest: TATest;


implementation

{$R *.DFM}


function HandlerEvent(eType : DWORD):boolean;
begin
  ShowMessage(Format('eType %d',[eType]));
  result := true;
end;

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  ATest.Controller(CtrlCode);
end;

function TATest.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TATest.ServiceStart(Sender: TService; var Started: Boolean);
begin
  if SetConsoleCtrlHandler(@HandlerEvent, true) then showmessage('ok');
  Started := true;
end;

procedure TATest.ServiceShutdown(Sender: TService);
begin
  SetConsoleCtrlHandler(@HandlerEvent, false);
end;

end.
 
0
 

Author Comment

by:mappemuppe
ID: 7176679
Thanks that was just what I needed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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