6

I have a ServiceInstall component in a WiX installer where I have a requirement to either start auto or demand depending on parameters passed into the MSI.

So the Xml element in question is

<ServiceInstall Vital="yes"
     Name="My Windows Service"
     Type="ownProcess"
     Account="[SERVICEUSERDOMAIN]\[SERVICEUSERNAME]"
     DisplayName="My Service"
     Password="[SERVICEUSERPASSWORD]"
     Start="demand"
     Interactive="no"
     Description="Something interesting here"
     Id="Service"
     ErrorControl="ignore"></ServiceInstall>

WiX will not allow using a PArameter for the Start attribute, so Im stuck with completely suplicating the component with a condition, eg/

<Component Id="ServiceDemand"
                 Guid="{E204A71D-B0EB-4af0-96DB-9823605050C7}" >
        <Condition>SERVICESTART="demand"</Condition>    
...

and completely duplicating the whole component, with a different setting for Start and a different Condition.

Anyone know of a more elegant solution? One where I don;t have to maintain 2 COmponents whjich do exactly the same thing except the Attribute for Start?

kanaka
  • 70,845
  • 23
  • 144
  • 140
Jamiec
  • 133,658
  • 13
  • 134
  • 193

2 Answers2

6

The Start field in the ServiceInstall table isn't formatted so what you are putting in with a property will not work. This link has some helpful suggestions that might get you through it: ServiceInstall - Start element. Looks like the person who posted had the same issue. My favorite suggestion they provide is to create a custom action that runs before InstallServices action that will change the value of the Start element in the Service Install table.

Update: Modified the link to the suggested site.

Scott Boettger
  • 3,657
  • 2
  • 33
  • 44
  • Thanks for the link/info. I'll do as suggested with a CA I think. – Jamiec Mar 24 '10 at 13:10
  • I find that a lot my questions can be answered by those guys. Here another good site that I use often. http://blogs.technet.com/alexshev/pages/from-msi-to-wix.aspx – Scott Boettger Mar 24 '10 at 19:20
  • Nabble link is now broken. Search on ServiceInstall-Start-element should get you a link to the relocated document on wix or nabble. – Greg Domjan Apr 04 '11 at 23:28
  • @Scott Boettger can you comment on why modifying the Start element in ServiceInstall table was your favorite suggestion, as opposed to duplicating the install-time Condition on Component/File ? Are you saying that in a CA you open the running MSI database and modify the ServiceInstall table? I'm just fishing for some insight on which route I should take. It gets tricky to make these decisions when my installs all use Heat with transforms. – JohnZaj Apr 25 '16 at 16:15
  • @jJack In the above question he stated that he did not want to maintain 2 Components that do exactly the same thing. It is completely viable to do it that way but for the sake of his preference that is why I chose the CA as my favorite suggestion for him. – Scott Boettger May 02 '16 at 11:48
1

Unfortunately standard Wix functionality to install and control services is pretty limited.

Though not ideal but it can be done using CustomAction, for example using CAQuietExec (which also conveniently saves output to installation log file if you use one)

  <CustomAction Id="QtExec_Install_Cmd" Property="QtExec_Install" Value="sc create [SERVICE_NAME] binPath=&quot;[INSTALLFOLDER]$(var.MAIN_EXECUTABLE)&quot; start=[SERVICE_START_FLAG]" Execute="immediate" />
  <CustomAction Id="QtExec_Install" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no" />
  <CustomAction Id="QtExec_Uninstall_Cmd" Property="QtExec_Uninstall" Value="sc delete [SERVICE_NAME]" Execute="immediate" />
  <CustomAction Id="QtExec_Uninstall" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no" />
  <InstallExecuteSequence>
    <Custom Action="QtExec_Install_Cmd" After="CostFinalize"/>
    <Custom Action="QtExec_Install" After="InstallServices">&amp;WindowsService=3</Custom>
    <Custom Action="QtExec_Uninstall_Cmd" After="CostFinalize"/>
    <Custom Action='QtExec_Uninstall' Before="RemoveFiles">NOT &amp;WindowsService=3 AND NOT &amp;WindowsService=-1</Custom>
  </InstallExecuteSequence>

Note:

  • WindowsService is the name of the Feature

  • SERVICE_START_FLAG is the property that controls whether to start service

  • [INSTALLFOLDER]$(var.MAIN_EXECUTABLE) - is the path to executable

  • SERVICE_NAME is the desired name for the Windows service

Ivan
  • 9,089
  • 4
  • 61
  • 74
  • Wow thanks for answer. Nearly 7 years late, but I'm sure it'll help someone out :) – Jamiec Jan 18 '17 at 10:55
  • Haha... I've been using Wix for ages now... probably should stop now... it's a shame there's no proper alternative from Microsoft, and your question is still valid. – Ivan Jan 18 '17 at 11:14