XN16
XN16

Reputation: 5869

WiX Service Install with user credentials or LocalSystem depending on UI input

Below is a section of my .wxs installer file which installed my service. I have a WiX UI dialog where the user can either choose to install the service to run under the LocalSystem account or input the credentials of the account they want. The UI has two text boxes (one bound to the ACCOUNT property and one to the PASSWORD property) and a checkbox that is bound to a property called USELOCALSYSTEMACCOUNT.

Individually, these service installers work fine, you can see both ServiceInstall sections below. However I want the installer to install the service with the user input credentials if USELOCALSYSTEMACCOUNT is not set to 1, or to use the LocalSystem account if USELOCALSYSTEMACCOUNT is set to 1, but I am unsure how to do this. the Condition tag doesn't work within a ServiceInstall tag so I'm a bit lost on how to achieve this.

WiX component section below:

<Component Id='MainExe' Guid='*'>
  <File Id='MainService' 
        Name='MyService.exe'
        Source='$(var.ServiceRoot2)\SA.MyService.exe'/>
    <ServiceInstall Id='MyService' 
                    Type='ownProcess' 
                    Vital='yes' Name='MyService' 
                    Name='$(var.HumanProductName)' 
                    Description='$(var.ProductDescription)' 
                    Start='demand' 
                    Account='[ACCOUNT]' 
                    Password='[PASSWORD]' 
                    ErrorControl='ignore' 
                    Interactive='no'/>
    <ServiceInstall Id='MyService' 
                    Type='ownProcess' 
                    Vital='yes' 
                    Name='$(var.HumanProductName)'  
                    Description='$(var.ProductDescription)' 
                    Start='demand' 
                    Account='LocalSystem' 
                    ErrorControl='ignore' 
                    Interactive='no'/>
    <ServiceControl Id='MyServiceServiceControl' 
                    Stop='both' 
                    Remove='both' 
                    Name='$(var.HumanProductName)' 
                    Wait='yes'/>
</Component>

Upvotes: 2

Views: 3050

Answers (1)

Brian Sutherland
Brian Sutherland

Reputation: 4798

You should be able to put the condition around the entire component and just have the LocalSystem version and the User specified version. Wix is smart enough to not package the Myservice.exe twice in the installer. Just make sure your condition has "OR Installed" appended to it because I've had issues in the past with conditional components/features not uninstalling because the property they depended on was not set during uninstall. If it is a state of the machine (VersionNT/VersionVT64 which remain constant) then omitting "OR Installed" should be fine.

Upvotes: 4

Related Questions