Solved

My service won't start - error 1053

Posted on 2004-08-22
10
2,275 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

15 Experts available now in Live!

Get 1:1 Help Now