unit uMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
TTestservice =
class(TService)
procedure ServiceStart(Sender: TService;
var Started: Boolean);
procedure ServiceCreate(Sender: TObject);
procedure ServiceExecute(Sender: TService);
procedure ServiceDestroy(Sender: TObject);
private
{ Private-Deklarationen }
LogFile: TStringList;
public
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
Testservice: TTestservice;
implementation
{$R *.DFM}
const LogFileName = '
Service_log.txt';
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
Testservice.Controller(CtrlCode);
end;
function TTestservice.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TTestservice.ServiceCreate(Sender: TObject);
begin
LogFile:=TStringList.Create;
end;
procedure TTestservice.ServiceDestroy(Sender: TObject);
begin
LogFile.Free;
end;
procedure TTestservice.ServiceExecute(Sender: TService);
begin
while not Terminated
do
begin
ServiceThread.ProcessRequests(False);
Sleep(5000);
LogFile.Add(DateTimeToStr(Now)+'
OnExecute');
LogFile.SaveToFile(LogFileName);
end;
end;
procedure TTestservice.ServiceStart(Sender: TService;
var Started: Boolean);
begin
LogFile.Add(DateTimeToStr(Now)+'
Service gestartet');
LogFile.SaveToFile(LogFileName);
end;
end.