Creating a Windows Service in Delphi - Entire Code for the Service Application
(Page 5 of 5 )
unit diskmon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
SvcMgr, Dialogs,
ExtCtrls;
type
TService1 = class(TService)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ServiceExecute(Sender: TService);
private
{ Private declarations }
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.Timer1Timer(Sender: TObject);
const
FileName = 'c:\logdate.txt';
var
F: TextFile;
begin
AssignFile(f,FileName);
if FileExists(FileName) then Append(f)
else
Rewrite(f);
writeln(f,DateTimeToStr(Now));
ShowMessage(DateTimeToStr(Now));
CloseFile(f);
end;
procedure TService1.ServiceExecute(Sender: TService);
begin
Timer1.Enabled := True;
while not Terminated do
ServiceThread.ProcessRequests(True);// wait for termination
Timer1.Enabled := False;
end;
end.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |