简体   繁体   中英

Set service account condition in wix if username and password is given

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>

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>

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