2

i created a service manager application that allows to install (with SC CREATE), start (using a code very similar to the one in the answer to:How to start a windows service in Delphi for Windows 8), stop and uninstall a service.

The service is a windows server exe app written in Delphi.

Suddenly (a few days ago) i was not able to start the service anymore on a specific machine (a Windows Server 2012R2), this occurs both from my application than from windows service console.

The same exes (manager and service) work fine on other machines (in particular another Windows Server 2012R2 and my windows 10 workstation) .

This is what i "measured":

1) when i try to start the service this code StartService(schs,0,psTemp) (WinAPI call - refer to link above) does not return true;

2) if i put OutpuDebugString messages in the dpr i cannot see them in DebugView, meaning that the service exe is not started

3) in the windows System event logger i see that there is a 30 seconds timeout while tryin to connect to the service

4) even if i create a dummyservice.exe that does nothing but writing some OutpuDebugString i am not able to start it

This is the implementation of the dummy service:

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

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

procedure TDummy.ServiceAfterInstall(Sender: TService);
begin
   OutputDebugString('ServiceAfterInstall');
end;

procedure TDummy.ServiceAfterUninstall(Sender: TService);
begin
  OutputDebugString('ServiceAfterUninstall');
end;

procedure TDummy.ServiceBeforeInstall(Sender: TService);
begin
  OutputDebugString('ServiceBeforeInstall');
end;

procedure TDummy.ServiceBeforeUninstall(Sender: TService);
begin
   OutputDebugString('ServiceBeforeUninstall');
end;

procedure TDummy.ServiceExecute(Sender: TService);
var
  cnt : Integer;
begin
  cnt :=0;
  while not Terminated do
  begin
    inc(CNT);
    OutputDebugString(Pwidechar('ServiceExecute  Count '+IntTOstr(Cnt)));
    Sleep(1000);
    ServiceThread.ProcessRequests(False);
  end;

end;

procedure TDummy.ServiceStart(Sender: TService; var Started: Boolean);
begin
  OutputDebugString('ServiceStart');
end;

procedure TDummy.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
  OutputDebugString('ServiceStop');
end;

On this specific machine two weeks ago i was able to start the service, nothing particular has been done.

I wonder what i can do to debug more, i am stuck.

Why there is a timeout, it seems my service exe is not even started (if it were i guess I would see the OutputDebugString messages in DebugView)?

This happens on one machine only, on one machine that up to a few days ago was performing normally.

Thanks to anyone who can help!

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • 1
    What does `GetLastError()` return when `StartService()` fails? Has there been any updates or new software installed recently on the machine that the service is failing on? – Remy Lebeau Sep 17 '19 at 10:06
  • I get error 1053 (the title of this question: https://stackErrooverflow.com/questions/158371/error-1053-the-service-did-not-respond-to-the-start-or-control-request-in-a-tim) calling `intToStr(GetLastError)+': '+ SysErrorMessage(GetLastError)` just after `StartService()`, and that is the same error i see in the windows event log. No apps have been installed, i appleid windows updates (minor ones) to try to fix the problem, but the problem was there before that. – UnDiUdin Sep 17 '19 at 11:43
  • 1
    Check your AntiVirus software. Many AV programs will block service execution if it is detected as posibly harmfull. Some might even block other programs that are trying to launch trusted services. – SilverWarior Sep 17 '19 at 12:17
  • @SilverWarior on this machine there is no AV software installed. – UnDiUdin Sep 17 '19 at 13:01
  • I also forced all Pending WIndows Updates but the situation did not change. Any idea? – UnDiUdin Sep 17 '19 at 13:26
  • Are you sure there's no AV running? Windows forcibly enables Windows Defender if it doesn't find another AV installed. – Jerry Dodge Sep 17 '19 at 13:37
  • @LaBracca Wait you are running Windows Server without any AV protection? Are you serious? That is just crazy. This actually opens a great chance that your server might be already infected with a virus which might be interfeering with your program or worse. – SilverWarior Sep 18 '19 at 05:43
  • I am not the IT manager and he finalized not to use AV software, by the way this is a database server not accessed by any normal user. This is OffTopic by the way. – UnDiUdin Sep 18 '19 at 09:31
  • The link to the question is https://stackoverflow.com/questions/158371/error-1053-the-service-did-not-respond-to-the-start-or-control-request-in-a-tim – Yennefer Sep 23 '20 at 16:12

0 Answers0