How to toggle between two usernames in a Wix service installer?

203 views Asked by At

I'm using Wix to install a windows service, but need the option for it to use the LocalSystem account or use an account provided by the user. How should I toggle between a hard coded value and the user value? For the service I have:

<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="[SERVICELOGONUSER]" Password="[SERVICELOGONPASSWORD]" ErrorControl="normal" 
    Interactive="no"/>

In the UI I have the property:

<Property Id="SERVICELOGONUSER" Value="LocalSystem"/>

In a dialog I have:

<Control Type="CheckBox" Width="200" Height="25" X="25" Y="75" Id="LocalCheckBox" 
    Property="UseLocalSystem" CheckBoxValue="1" Text="Use LocalSystem Account"/>
<Control Type="Edit" Width="200" Height="15" X="25" Y="115" Id="AccountTextbox" 
    Property="SERVICELOGONUSER">
    <Condition Action="disable">UseLocalSystem = 1</Condition>
    <Condition Action="enable"><![CDATA[UseLocalSystem <>1]]></Condition
</Control>

But this will just display the hard coded value, which the user can edit.

1

There are 1 answers

0
Ryan Quasney On BEST ANSWER

I would advise making two components with mutually exclusive conditions using your UseLocalSystemproperty, like this:

<Component Id="LocalSystem_Service" Guid="{A-GUID}">
  <Condition> UseLocalSystem = 1 </Condition>
  <File Id="SvcFile_Local" Name="Service.exe" Source="Service.exe"/>
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="LocalSystem" ErrorControl="normal" Interactive="no"/>
</Component>

<Component Id="User_Service" Guid="{ANOTHER-GUID}">
  <Condition> <![CDATA[UseLocalSystem <>1]]> </Condition>
  <File Id="SvcFile_User" Name="Service.exe" Source="Service.exe" />
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="[SERVICELOGONUSER]" Password="[SERVICELOGONPASSWORD]" ErrorControl="normal" 
    Interactive="no"/>
</Component>

WiX has a limitation where if you need the same file in two places, you need to have a File element for it in each place, which is why I have two File elements with different Id's. No worries though, thanks to smart cabbing, WiX toolset will only compress the duplicated content across the Components once.

This way, it won't matter if the user starts to change the SERVICELOGONUSER and SERVICELOGONPASSWORD and decide to use LocalSystem instead.

Hope this helps!