2

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

ChickenFeet
  • 2,653
  • 22
  • 26

3 Answers3

2

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.

Bob Arnson
  • 21,377
  • 2
  • 40
  • 47
  • I thought as much. Why do they even let you access the `ServiceConfig` outside of a `ServiceInstall` element if the functionality won't work, seems kind of counterproductive. The question doesn't explicitly ask for `ServiceConfig` solutions, but I appreciate the information :) – ChickenFeet Dec 05 '17 at 01:22
2

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.

ChickenFeet
  • 2,653
  • 22
  • 26
0

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

Calum MacLeod
  • 443
  • 3
  • 11