2

我创建了一个服务管理器应用程序,它允许安装(使用 SC CREATE)、启动(使用与答案中的代码非常相似的代码:How to start a windows service in Delphi for Windows 8)、停止和卸载服务。

该服务是一个用 Delphi 编写的 windows 服务器 exe 应用程序。

突然(几天前)我无法再在特定机器(Windows Server 2012R2)上启动该服务,这发生在我的应用程序而不是 Windows 服务控制台。

相同的 exe(管理器和服务)在其他机器(特别是另一台 Windows Server 2012R2 和我的 Windows 10 工作站)上运行良好。

这就是我“测量”的:

1)当我尝试启动服务时,此代码StartService(schs,0,psTemp)(WinAPI 调用 - 请参阅上面的链接)不返回 true;

2)如果我将OutpuDebugString消息放入 dpr 我无法在DebugView中看到它们,这意味着服务 exe 未启动

3)在 Windows 系统事件记录器中,我看到尝试连接到服务时有 30 秒超时

4)即使我创建了一个 dummyservice.exe,除了写一些OutpuDebugString我什么都不做,我也无法启动它

这是虚拟服务的实现:

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;

两周前在这台特定的机器上我能够启动服务,没有做任何特别的事情。

我想知道我能做些什么来调试更多,我被卡住了。

为什么超时,似乎我的服务 exe 甚至没有启动(如果是我猜我会OutputDebugString在 DebugView 中看到消息)?

这只发生在一台机器上,一台机器上几天前运行正常。

感谢任何能提供帮助的人!

4

0 回答 0