Példa

Top  Previous  Next

//*******************************************************//

//                                                       //

//         Delphi Software Online                        //

//         internetes hetilap példaprogram               //

//         http://www.animare.hu/dso/                    //

//                                                       //

//         Animare Software © 2000                       //

//         http://www.animare.hu                         //

//                                                       //

//*******************************************************//

unit Unit1;

 

interface

 

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

 

type

TService2 = class(TService)

  procedure Service1Execute(Sender: TService);

  procedure Service2AfterInstall(Sender: TService);

  procedure Service2AfterUninstall(Sender: TService);

  procedure Service2BeforeInstall(Sender: TService);

  procedure Service2BeforeUninstall(Sender: TService);

  procedure Service2Continue(Sender: TService; var Continued: Boolean);

  procedure Service2Create(Sender: TObject);

  procedure Service2Destroy(Sender: TObject);

  procedure Service2Pause(Sender: TService; var Paused: Boolean);

  procedure Service2Shutdown(Sender: TService);

  procedure Service2Start(Sender: TService; var Started: Boolean);

  procedure Service2Stop(Sender: TService; var Stopped: Boolean);

private

  FI: integer;

  procedure Log(s: string);

 

public

  function GetServiceController: PServiceController; override;

  { Public declarations }

end;

 

var

Service2: TService2;

 

implementation

 

 

{$R *.DFM}

 

procedure ServiceController(CtrlCode: DWord); stdcall;

begin

Service2.Controller(CtrlCode);

end;

 

function TService2.GetServiceController: PServiceController;

begin

Result := @ServiceController;

end;

 

procedure TService2.Service1Execute(Sender: TService);

begin

while not Terminated do begin

  Windows.Beep(800, 100);

  Windows.Beep(100, 500);

  Windows.Beep(1200, 30);

  Sleep(1000);

  ServiceThread.ProcessRequests(false);

end;

end;

 

procedure TService2.Service2AfterInstall(Sender: TService);

begin

Log('AfterInstall');

end;

 

procedure TService2.Service2AfterUninstall(Sender: TService);

begin

Log('AfterUninstall');

end;

 

procedure TService2.Service2BeforeInstall(Sender: TService);

begin

Log('BeforeInstall');

end;

 

procedure TService2.Service2BeforeUninstall(Sender: TService);

begin

Log('BeforeUninstall');

end;

 

procedure TService2.Service2Continue(Sender: TService; var Continued: Boolean);

begin

Log('Continue');

end;

 

procedure TService2.Service2Create(Sender: TObject);

begin

FI:=40;

Log('Create');

end;

 

procedure TService2.Service2Destroy(Sender: TObject);

begin

Log('Destroy');

end;

 

procedure TService2.Service2Pause(Sender: TService; var Paused: Boolean);

begin

Log('Pause');

end;

 

procedure TService2.Service2Shutdown(Sender: TService);

begin

Log('Shutdown');

end;

 

procedure TService2.Service2Start(Sender: TService; var Started: Boolean);

begin

Log('Start');

end;

 

procedure TService2.Service2Stop(Sender: TService; var Stopped: Boolean);

begin

Log('Stop');

end;

 

procedure TService2.Log(s: string);

var

st: TFileStream;

a: array[0..512] of char;

begin

s:='- '+DateTimeToStr(Now)+' '+s+#13+#10;

StrPCopy(a, s);

try

  st:=TFileStream.Create('c:\log.txt', fmOpenReadWrite);

except

  st:=TFileStream.Create('c:\log.txt', fmCreate);

end;

st.Seek(0, soFromEnd);

st.Write(a, Length(s));

st.Free;

end;

 

end.