0

I have a wix installer for windows service. According to requirement, if domain name,username and password all of these are given then the service should be installed with that user account else the service should run with local system after installation.

How to set Account based on condation? Below is the code for service installation:

<Component Id="CMPFa85281c3_a329_4a93_a1d7_203fbccec31f" Guid="*" Directory="INSTALLLOCATION">
  <Condition>
    <![CDATA[Installed OR (SVCINSTALL <> 0)]]>
  </Condition>
  <RemoveFile Id="RmFa85281c3_a329_4a93_a1d7_203fbccec31f" Name="MyService.exe" On="both" />
  <File Id="Fa85281c3_a329_4a93_a1d7_203fbccec31f" Source="$(var.BaseDir)\MyService.exe" KeyPath="yes" />

  <ServiceInstall Id="InstallWindowsService" Name="$(var.SvcName)" 
                  DisplayName="$(var.SvcDisplayName)"
                  Start="auto" 
                  ErrorControl="normal" 
                  Type="ownProcess"
                  Account="LocalSystem"
                  Description="$(var.SvcDescription)"/>

  <ServiceControl Id="sc_InstallWindowsService" Name="$(var.SvcName)" Start="install" Remove="uninstall" Stop="both" Wait="no"/>

</Component>
Microsoft Developer
  • 5,229
  • 22
  • 93
  • 142

1 Answers1

2

I would add two components that are identical except for the ServiceInstall element and condition the components so only one is installed. Like:

<Condition>DOMAINNAME And USERNAME And PASSWORD</Condition>

And the opposite:

<Condition>Not(DOMAINNAME And USERNAME And PASSWORD)</Condition>
tjleigh
  • 1,134
  • 1
  • 10
  • 23