service 程序(100分)

  • 主题发起人 主题发起人 daili
  • 开始时间 开始时间
D

daili

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi5支持NT下services 程序,帮助很少,想看看事例或相关资料,或有高手相助。
 
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.
 
接受答案了.
 
后退
顶部