Service start function parameter in the WiX installer

I have a ServiceInstall component in the WiX installer, where I have a requirement to either start auto, or depending on the parameters passed to 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 PArameter to be used for the Start attribute, so Im stuck with a fully complemented component with a condition like /

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

and completely duplicates the entire component with a different setting for Start and another condition.

Does anyone know a more elegant solution? One where I should not support 2 COmponents that do the same except for the attribute to run?

+6
wix windows-services
source share
2 answers

The Start field in the ServiceInstall table is not formatted, so what you insert into the property will not work. This link contains some useful tips to help you with this: ServiceInstall - a startup item . It seems that the one who posted had the same problem. My favorite suggestion they provide is to create a custom action that runs before the InstallServices action, which changes the value of the Start element in the Service installation table.

Update: Changed the link to the proposed site.

+6
source share

Unfortunately, the standard Wix functionality for installing and managing services is rather limited.

Although this is not ideal, it can be done using CustomAction, for example, using CAQuietExec (which also conveniently saves the output to the installation log file if you use it)

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

  • SERVICE_START_FLAG is a property that controls the start of a service

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

  • SERVICE_NAME - desired name of the Windows service

0
source share

All Articles