Hola, buenas tardes.
He buscado en el foro y se habla mucho de este tema, pero no he sabido encontrar la respuesta de el porqué no arranca.
Este sería el código, más o menos parecido a alguno que he visto en el foro:
Código Delphi
[-]program Project1;
uses
Vcl.SvcMgr,
Unit1 in 'Unit1.pas' ;
{$R *.RES}
begin
if not Application.DelayInitialize or Application.Installing then
Application.Initialize;
Application.CreateForm(TService1, Service1);
Application.Run;
end.
Código Delphi
[-]unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.SvcMgr, Vcl.Dialogs,
extctrls;
type
TService1 = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
tmr :TTimer;
private
procedure Ontimer(Sender: TObject);
procedure WriteLog(cMsg:String);
public
function GetServiceController: TServiceController; override;
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.ServiceStart(Sender: TService; var Started: Boolean);
begin
beep;
WriteLog('ServiceStart');
tmr:=TTimer.Create(nil);
tmr.Interval:=1000;
tmr.OnTimer:=Ontimer;
tmr.Enabled:=true;
Started:=true;
end;
procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
beep;
WriteLog('ServiceStop');
if assigned(tmr) then
begin
tmr.Enabled:=false;
freeandnil(tmr);
end;
Stopped:=true;
end;
procedure TService1.Ontimer(Sender: TObject);
begin
beep;
WriteLog('Ontimer');
end;
procedure TService1.WriteLog(cMsg:String);
var
myFile : TextFile;
cFile : string;
begin
Try
cFile := 'C:\Users\Papá\Desktop\Desarrollo\Documentos\DOCs\Service_Test.txt';
AssignFile(myFile, cFile);
if fileExists(cFile) then
Append(myfile)
else
ReWrite(myFile);
WriteLn(myFile, FormatDateTime('yyyy-mmm-dd hh:mm:ss',now)+ ' '+ cMsg);
finally
CloseFile(myFile);
end;
end;
end.
¿Podéis ver el motivo?
Muchas Gracias.