How to change the Windows service startup type in a WiX installer

筅森魡賤 提交于 2019-12-20 16:23:30

问题


We need to modify the Startup type of our Windows service from "Automatic" to "Automatic Delayed Start". How do I do this?

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.


回答1:


Place a ServiceConfig element within the ServiceInstall element.

<ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" />



回答2:


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.

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



来源:https://stackoverflow.com/questions/3763596/how-to-change-the-windows-service-startup-type-in-a-wix-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!