Set service Startup type in WiX installer

2019-07-12 09:00发布

问题:

I am trying to set a pre-installed service's startup type to Automatic, using WiX. Another task was to start the service on install, which I achieved with:

<ServiceControl 
    Id="ServiceRunningState" 
    Name="[Service Name]" 
    Start="install"
    Stop="install"
    Wait="yes" /> 

Now I would also like to set the startup type. I have tried the following (see answer):

<ServiceConfig
    Id="ServiceStartup" 
    ServiceName="[Service Name]"
    DelayedAutoStart="yes"
    OnInstall="yes" 
    OnReinstall="yes" />

But this didn't change the startup type of the service (tested from Manual startup type). And besides, I want the startup type to be Automatic, not Automatic (Delayed Start).

Please note that I am trying to modify an existing service, so there is no ServiceInstall element.

The two elements (ServiceControl and ServiceConfig) are children within a Component parent element.

Any help is appreciated :)

回答1:

MSI doesn't support changing the startup type of a service that the package doesn't install. ServiceConfig doesn't let you get around that:

Applies only to installed auto-start services or services installed by this package with SERVICE_AUTO_START in the StartType field of the ServiceInstall table.



回答2:

Set the "DelayedAutoStart" parameter to "no", rather than "yes".



回答3:

Solved by editing the registry via RegistryKey, see example:

<RegistryKey Root="HKLM"
             Key="SYSTEM\CurrentControlSet\Services\[Service Name]"
             Action="create">
    <RegistryValue Type="integer" Name="Start" Value="2" />
    <RegistryValue Type="integer" Name="DelayedAutostart" Value="0" />
</RegistryKey>

Note service may appear as Automatic (Delayed Start) in Services GUI. However, after restarting, Services GUI displayed the service startup type as Automatic.