如何在 WiX 安装程序中更改 Windows 服务启动类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3763596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the Windows service startup type in a WiX installer
提问by Ray
We need to modify the Startup type of our Windows service from "Automatic" to "Automatic Delayed Start". How do I do this?
我们需要将 Windows 服务的启动类型从“自动”修改为“自动延迟启动”。我该怎么做呢?
My code is like this:
我的代码是这样的:
<ServiceInstall
Id="WinServiceInstall"
Name="ServiceManager"
DisplayName="ServiceManager"
Type="ownProcess"
Start="auto"
ErrorControl="normal"
Vital ='yes'
Description ='Monitoring and running the jobs'
Account="[SERVICEACCOUNT]"
Password="[SERVICEPASSWORD]">
<util:ServiceConfig
FirstFailureActionType="restart"
SecondFailureActionType="restart"
ThirdFailureActionType ="restart"
cRestartServiceDelayInSeconds ="10" />
</ServiceInstall>
And how do I set the Restart service time? I would like to set Restart service after 2 minutes if failed.
以及如何设置重启服务时间?如果失败,我想在 2 分钟后设置重新启动服务。
回答by Matthew Sharpe
Place a ServiceConfig
element within the ServiceInstall
element.
在ServiceConfig
元素内放置一个ServiceInstall
元素。
<ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" />
回答by Dave Andersen
I couldn't figure out how to get the service to use "Automatic Delayed Start" with the ServiceInstall element (since it isn't an option in the enumeration), so I ended up setting it with a reg-value.
我不知道如何让服务使用带有 ServiceInstall 元素的“自动延迟启动”(因为它不是枚举中的一个选项),所以我最终用一个 reg 值设置了它。
<RegistryValue Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\[ServiceName]"
Type="integer" Name="DelayedAutostart" Value="1"/>
I put this in the same component as the ServiceInstall, and everything seems to work fine. I imagine you could do the same thing for the service restart time.
我把它放在与 ServiceInstall 相同的组件中,一切似乎都正常。我想你可以为服务重启时间做同样的事情。