Solved

My service won't start - error 1053

Posted on 2004-08-22
10
2,299 Views
Last Modified: 2008-01-09
Hi,

I write my first service with delphi 7. I can install it but when I try to start it I receive an error 53. The
Service did not respond to the start or control request in a timely fashion.

I can't find the issue. Here is my code :

unit uServProj;

interface

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

type
  TServProj = class(TService)
    Timer1: TTimer;
    procedure ServiceExecute(Sender: TService);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;


var
  ServProj: TServProj;

const FileName = 'c:\logfile.txt';

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  ServProj.Controller(CtrlCode);
end;

function TServProj.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TServProj.ServiceExecute(Sender: TService);
begin

 timer1.Enabled := true;

 while not terminated do
 begin
  ServiceThread.ProcessRequests(true);
  timer1.Enabled := false;
 end;


end;

procedure TServProj.Timer1Timer(Sender: TObject);
var f : textfile;
begin

  AssignFile(f,filename);
  if FileExists(filename) then append(f)
  else
    Rewrite(f);

  writeln(f, 'kk');
  ShowMessage('');
  CloseFile(f);

end;

end.

What is wrong ?

Sang-Do
0
Comment
Question by:PHD
  • 4
  • 3
  • 2
10 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11863356
try this:

unit uServProj;

interface

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

type
  TServProj = class(TService)
    Timer1: TTimer;
    procedure ServiceExecute(Sender: TService);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  ServProj: TServProj;

const FileName = 'c:\logfile.txt';

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  try
    ServProj.Controller(CtrlCode);
  except
    on E : Exception do
      ShowMessage(E.Message + ' ServiceController');
  end;
end;

function TServProj.GetServiceController: TServiceController;
begin
  try
    Result := ServiceController;
  except
    on E : Exception do
      ShowMessage(E.Message + ' GetServiceController');
  end;
end;

procedure TServProj.ServiceExecute(Sender: TService);
begin
  try
    timer1.Enabled := true;

    while not terminated do
    begin
      ServiceThread.ProcessRequests(true);
      timer1.Enabled := false;
    end;
  except
    on E : Exception do
      ShowMessage(E.Message + ' ServiceExecute');
  end;
end;

procedure TServProj.Timer1Timer(Sender: TObject);
var f : textfile;
begin
  try
    AssignFile(f,filename);
    if FileExists(filename) then append(f)
    else
      Rewrite(f);

    writeln(f, 'kk');
    ShowMessage('');
    CloseFile(f);
  except
    on E : Exception do
      ShowMessage(E.Message + ' Timer1Timer');
  end;
end;

end.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11863392
This way it will be localized the method where the error occurs ....
0
 
LVL 6

Author Comment

by:PHD
ID: 11863716
Thanks esoftbg but I tried your code but nothing happens.

I get no error message excepted the known error message : error 53... .

Sang-Do
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 12

Expert Comment

by:esoftbg
ID: 11863888
I can not test your code, because I never have been write a service ....
If you explain how to install, I will try your code on my computer (I am using Delphi 7 too)
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11866482
The message for error 1053 means "The service did not respond to the start or control request in a timely fashion"

When your service starts, it has to update its status to "started" (or "starting" with a progress indicator), otherwise if service control manager won't know when it is successfully started.
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 500 total points
ID: 11866497
try using  Self.Status := csRunning; in your ServiceExecute method. Status property is what you should see in Service Control Manager.
0
 
LVL 6

Author Comment

by:PHD
ID: 11867642

To install the service, I donwloaded Srvinstw.exe. When you run the program, a wizard will guide you.

Sang-Do
0
 
LVL 6

Author Comment

by:PHD
ID: 11878416

I also try this :

procedure TServProj.ServiceExecute(Sender: TService);
begin
  try
    timer1.Enabled := true;
    self.Status := csRunning;

    while not terminated do
    begin
      ServiceThread.ProcessRequests(true);
      timer1.Enabled := false;
    end;
  except
    on E : Exception do
      ShowMessage(E.Message + ' ServiceExecute');
  end;
end;

Including the status properties with no more success.

Sang-Do
0
 
LVL 6

Author Comment

by:PHD
ID: 11892686
Ok now it working fine.

The problem : The Displayname property did not match the name of the project.

My project's name is 'Service' and I set the displayname property to service instead of 'loggeduser' and then It starts as expected.

Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now