unit Unit1;
(*
Test Service Application - 12.28.99 - David Lively
Email dlively@intellecare.com
A simple service application that can be started, paused, continued, and stopped.
Beeps once every two seconds when executing. Install by running
"service /install" from the command line, then manipulate the service with:
START) net start "test service"
STOP) net stop "test service"
PAUSE) net pause "test service"
CONTINUE) net continue "test service"
To uninstall, run "service /uninstall"
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;
type
TService1 = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceExecute(Sender: TService);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
private
{ Private declarations }
fPaused : boolean;
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
Service1: TService1;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service1.Controller(CtrlCode);
end;
function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
begin
Started := TRUE;
end;
procedure TService1.ServiceExecute(Sender: TService);
begin
while not Terminated do begin
if not fPaused then begin
Sleep(100);
MessageBeep(0);
end;
ServiceThread.ProcessRequests(FALSE);
end;
end;
procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
ServiceThread.Terminate;
fPaused := TRUE;
Stopped := TRUE;
end;
procedure TService1.ServicePause(Sender: TService; var Paused: Boolean);
begin
Paused := True;
fPaused := TRUE;
end;
procedure TService1.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
Continued := True;
fPaused := FALSE;
end;
end.