unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
TTestservice =
class(TService)
procedure ServiceStart(Sender: TService;
var Started: Boolean);
procedure ServiceExecute(Sender: TService);
private
{ Private-Deklarationen }
public
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
Testservice: TTestservice;
LogFile: TStringList;
implementation
{$R *.DFM}
const LogFileName = '
c:\test\Service_log.txt';
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
Testservice.Controller(CtrlCode);
end;
function TTestservice.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TTestservice.ServiceExecute(Sender: TService);
begin
while not Terminated
do
begin
ServiceThread.ProcessRequests(true);
// 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;
initialization
LogFile:=TStringList.Create;
finalization
LogFile.Free;
end.