delphi-更改服务名称运行时 [英] delphi - changing service name runtime

查看:126
本文介绍了delphi-更改服务名称运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Delphi 10.2.3中创建了一个服务,它运行良好。

I created a service in Delphi 10.2.3 and it runs well.

要调试它,我在 dpr 文件中添加了它:

To debug it, I added this in the dpr file:

{$ifdef DEBUG}

    try
      // In debug mode the server acts as a console application.
      WriteLn('MyServiceApp DEBUG mode. Press enter to exit.');

      // Create the TService descendant manually.
      EseguiProcessiClient := TEseguiProcessiClient.Create(nil);

      // Simulate service start.
      EseguiProcessiClient.ServiceStart(EseguiProcessiClient, MyDummyBoolean);

      // Keep the console box running (ServerContainer1 code runs in the background)
      ReadLn;

      // On exit, destroy the service object.
      FreeAndNil(EseguiProcessiClient);
    except
      on E: Exception do
      begin
        Writeln(E.ClassName, ': ', E.Message);
        WriteLn('Press enter to exit.');
        ReadLn;
      end;
    end;
  {$else}
    if not Application.DelayInitialize or Application.Installing then
      Application.Initialize;
    Application.CreateForm(TEseguiProcessiClient, EseguiProcessiClient);
  Application.Run;
  {$endif}

这样,我可以毫无问题地对其进行调试。

This way, I can debug it without problems.

但是现在,我想在运行时更改服务名称,所以我遵循以下答案:

But now, I wanted to change the service name at runtime, so I followed this answer:

https://stackoverflow.com/a/612938/1032291

但是现在,当我在发布模式下运行服务时,如果保留原始名称(EseguiProcessiClient),则没有问题,但是如果将名称更改为其他名称,则该服务将无法启动。看起来它输入了 ServiceCreate 事件,但没有输入 ServiceStart 事件。

But now, when I run the service in Release mode, if I keep the original name (EseguiProcessiClient) I have no problems, but if I change the name to something else, the service does not start. It looks like it enters in the ServiceCreate event, but not in the ServiceStart event.

有人可以给我一些帮助吗?

Could anybody give me some help?

推荐答案

好,我我自己解决了。如我所说,问题出在 ImagePath 。我必须使用 sc create 自己创建服务,然后手动添加参数。

Ok, i solved it myself. As I said, the problem was the ImagePath. I had to create the service myself using sc create and adding the parameter manually.

这篇关于delphi-更改服务名称运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆