gpt4 book ai didi

Delphi服务启动方法

转载 作者:行者123 更新时间:2023-12-02 01:59:16 25 4
gpt4 key购买 nike

我有一个用 Delphi XE5 编写的 Windows 服务应用程序,并将 StartType 设置为 stAuto。有没有办法让服务检测它是在启动时自动启动还是手动启动?我有一个单独的管理器程序来执行安装、启动、停止和卸载。该服务需要知道启动是否来自管理器。我可以让经理在手动启动之前创建一个注册表项并将其用作我的测试,但想知道是否有更干净的解决方案。

最佳答案

I have a Windows Service app written in Delphi XE5 with StartType set to stAuto. Is there a way for the service to detect if it started automatically at bootup verses being started manually?

不完全是,不。开始就是开始,无论何时发出。然而...

I have a separate manager program that performs the install, start, stop, and uninstall. The service needs to know if the start came from the manager.

管理器在调用 StartService() 时可以包含额外的参数。然后,该服务可以在启动时枚举其 Param[] 属性,查找该参数。

I could have the manager make a registry entry just prior to the manual start and use that as my test but was wondering if there is a cleaner solution.

是的,有 - 使用 StartService()lpServiceArgVectors 参数:

dwNumServiceArgs

The number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.

lpServiceArgVectors

The null-terminated strings to be passed to the ServiceMain function for the service as arguments. If there are no arguments, this parameter can be NULL. Otherwise, the first argument (lpServiceArgVectors[0]) is the name of the service, followed by any additional arguments (lpServiceArgVectors[1] through lpServiceArgVectors[dwNumServiceArgs-1]).

关于Delphi服务启动方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69200598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com