开发者

How can I get the startup type of a service from InstallShield?

开发者 https://www.devze.com 2023-02-18 00:31 出处:网络
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 D

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 mi开发者_如何转开发ght 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?


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).


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消