如何从InstallShield获取服务的启动类型?

发布于 2024-10-25 23:54:22 字数 330 浏览 3 评论 0原文

我有一个 InstallScript 安装程序,需要根据现有服务的当前值修改其启动类型(即自动、手动或禁用)。例如,如果当前启动类型为“禁用”,则可能会保留该状态,否则可能会将其设置为“自动”。

不幸的是,我找不到获取服务启动类型的方法。有一些函数可以检测服务是否存在 (ServiceExistsService),并获取其当前的启动/停止状态 (ServiceGetServiceState),但没有任何函数可以检索服务的参数。我认为调用这些函数之一可能会填充 SERVICE_IS_PARAMS 结构作为副作用,但情况似乎并非如此。

如何获取服务的启动类型?

I have an InstallScript installer that needs to modify an existing service's startup type (i.e. Automatic, Manual or Disabled) based on its current value. For example, if the current startup type is Disabled, it might leave it so, while otherwise it might set it to Automatic.

Unfortunately I can't find a way to obtain a service's startup type. There are functions to detect whether a service exists (ServiceExistsService), and get its current started/stopped state (ServiceGetServiceState), but nothing that retrieves the service's parameters. I thought that perhaps calling one of those functions would populate the SERVICE_IS_PARAMS structure as a side-effect, but that doesn't seem to be the case.

How can I get a service's startup type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光与爱终年不遇 2024-11-01 23:54:22

不完全推荐,但实际上应该很容易从 HKLM\System\CurrentControlSet\Services\TheServiceName 读取此信息;特别是 DWORD Start 包含启动类型。请注意,直接在注册表中更改此项至少在重新启动之前不太可能产生影响,因此最好使用 API 来应用任何更改。

或者,如果您想做“正确”的事情,您可以声明到达 Advapi32.QueryServiceConfig。这将支持任何更改注册表位置或底层存储的 Windows 版本(这是我没想到的,但应该被认为是可能的)。

It's not exactly recommended, but in practice it should be easy enough to read this information from HKLM\System\CurrentControlSet\Services\TheServiceName; in particular the DWORD Start contains the startup type. Note that changing this in the registry directly is unlikely to affect things at least until after a reboot, so it's still good to use the API to apply any changes.

Alternately if you want to do things "right" you could declare the structures and functions necessary to get to Advapi32.QueryServiceConfig. This would support any version of Windows that changed the registry location or underlying storage (something I wouldn't expect, but it should be considered possible).

醉殇 2024-11-01 23:54:22

另一个选项是使用参数“service MyServiceName get StartMode”启动 WMIC.exe,并将输出重定向到文件,该选项速度较慢,但​​应该不会失败。然后,读取文件,第二行应包含答案(自动/手动/禁用)

Another option, which is slower but should be fail-proof, is to launch WMIC.exe with the parameters 'service MyServiceName get StartMode' and redirect the output to a file. Then, read the file and the 2nd line should contain the answer (Auto/Manual/Disabled)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文