Below is an application for servicing bare bones.
Please note that if you want to install the service on Windows Vista and higher using ServiceApp.exe / installation, you must make sure that you run the application with administrator rights.
Also note that despite fmShareDenyWrite, the contents of the log file may not be displayed while the service is running. At least I could not open the file using Notepad ++ until I stopped the service. This may be due to the fact that I had a service running under a system account (unlike my user account).
One more note: If you want your service to be paused and continued, do not use pause and resume. They are not thread safe and are deprecated in D2010 +. Using the T (Simple) event or something similar to control the execution of the main workflow. If you do not want your service to be suspended and continued, you can simply set AllowPause to False.
unit ServiceApp_fm; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs; type TService1 = class(TService) procedure ServiceStart(Sender: TService; var Started: Boolean); procedure ServiceStop(Sender: TService; var Stopped: Boolean); private FWorker: TThread; public function GetServiceController: TServiceController; override; end; var Service1: TService1; implementation {$R *.DFM} type TMainWorkThread = class(TThread) private {$IFDEF UNICODE} FLog: TStreamWriter; {$ELSE} FLog: TFileStream; {$ENDIF} FRepetition: Cardinal; public constructor Create; destructor Destroy; override; procedure Execute; override; end; 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 FWorker := TMainWorkThread.Create; Started := True; end; procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean); begin
source share