开发者

Parameterise Service start option in WiX installer

开发者 https://www.devze.com 2022-12-23 16:56 出处:网络
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.

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消