Search code examples
installationwixwindows-serviceswix3.5

WIX setup with user input


I've struggled with WIX for some time now. I want my program to be installed at the location the user has defined, install a service and start a program after installation.

First my msi package doesn't ask for install path.

<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder">
    <Directory Id="INSTALLFOLDER" Name="Test" />
  </Directory>
</Directory>
</Fragment>

May someone tell me how to prompt a screen with change install path?

Second when my service will be installed there is an error which says I miss some permissions:

<File Id="FILE_Service" Source="$(var.Service.TargetPath)" />
    <ServiceInstall Id="INSTALL_Service"
                    Name="Servcie"
                    Description=""
                    Start="auto"
                    ErrorControl="normal"
                    Type="ownProcess"/>

    <ServiceControl Id="CONTROL_Service"
                          Name="Servcie"
                          Start="install"
                          Stop="both"
                          Remove="uninstall"
                          Wait="yes" />

May someone tell me how to start my service with admin access?

Third the installed package contains only one EXE file, no referenced assembly. May someone tell me how to tell WIX to search for references and install them?


Solution

  • WiX Tutorial: Quite a bit here. You should try a WiX tutorial: https://www.firegiant.com/wix/tutorial/

    Links: Here is my WiX quick start tip answer - various resources and hints to deal with WiX and deployment in general.

    Please note that there are alternative deployment and package creation tools that might help you make setups quicker and more reliably if you have little experience with MSI and setups.


    Concrete Answer: Here are some attempted answers for your concrete questions:

    • Configurable installation directory (a bit down the page). You essentially set the ConfigurableDirectory attribute for a feature element to allow the user to select a custom installation directory (you get to the dialog where you can change the installation path by selecting "Custom" installation):

      <Feature Id="FeatureDirectory" Title="FeatureDirectory" ConfigurableDirectory="MYCUSTOMDIR">
           <!-- your stuff here -->
      </Feature>
      
    • Major Upgrade Installation Directory: You need to read back the custom directory for major upgrades. Here is how: The WiX toolset's "Remember Property" pattern. Or it will revert to default during the major upgrade. This is because a major upgrade is an uninstall of the old version and a (re)-install of the new version.

    • Files: To install all required files you need to figure out by dependency scanning what files need to be deployed for your application to work, and then add them to your packages manually (or use heat.exe to auto-generate the files list to include). See the above quick start links for help, or see this hello wix style article: https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with

    • Service Permissions: Services should be installed with admin rights if you install the setup after a UAC elevation prompt. Most likely it does not start because there are missing files and hence broken dependencies. What credentials does the service use to run? LocalSystem?


    Mock-Up: Here is a quick mock-up of something along the lines of what you need. You need to add all files and dependencies and insert the Service constructs among other things:

    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
      <Product Id="*" Name="WiXSample" Language="1033" Version="1.0.0.0"
               Manufacturer="Someone" UpgradeCode="cb24bedf-e361-4f25-9a06-ac84ce5d6f5c">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />
    
        <!--Default GUI - add reference to WixUIExtension.dll -->
        <UIRef Id="WixUI_Mondo" />
    
        <Feature Id="Core" Title="Core" Level="1" ConfigurableDirectory="INSTALLFOLDER" />
    
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="WiXSample">
              <Component Feature="Core">
                <File Source="D:\MyBinary.exe" />
              </Component>
            </Directory>
          </Directory>
        </Directory>
      </Product>
    
    </Wix>