简体   繁体   中英

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

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.

I would advise making two components with mutually exclusive conditions using your UseLocalSystem property, 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM