<p>How can I make a major upgrade to an installation set (MSI) built with <a href="http://en.wikipedia.org/wiki/WiX" rel="noreferrer">WiX</a> install into the same folder as the original installation?</p>

<p>The installation is correctly detected as an upgrade, but the directory selection screen is still shown and with the default value (not necessarily the current installation folder).</p>

<p>Do I have to do manual work like saving the installation folder in a registry key upon first installing and then read this key upon upgrade? If so, is there any example?</p>

<p>Or is there some easier way to achieve this in <a href="http://en.wikipedia.org/wiki/Windows_Installer" rel="noreferrer">MSI</a> or WiX?</p>

<p>As reference, I my current WiX file is below:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi"&gt;
    &lt;Product Id="a2298d1d-ba60-4c4d-92e3-a77413f54a53"
             Name="MyCompany Integration Framework 1.0.0"
             Language="1033"
             Version="1.0.0"
             Manufacturer="MyCompany"
             UpgradeCode="9071eacc-9b5a-48e3-bb90-8064d2b2c45d"&gt;

        &lt;!-- Package information --&gt;
        &lt;Package Keywords="Installer"
                 Id="e85e6190-1cd4-49f5-8924-9da5fcb8aee8"
                 Description="Installs MyCompany Integration Framework 1.0.0"
                 Comments="Installs MyCompany Integration Framework 1.0.0"
                 InstallerVersion="100"
                 Compressed="yes" /&gt;

        &lt;Upgrade Id='9071eacc-9b5a-48e3-bb90-8064d2b2c45d'&gt;
            &lt;UpgradeVersion Property="PATCHFOUND"
                            OnlyDetect="no"
                            Minimum="0.0.1"
                            IncludeMinimum="yes"
                            Maximum="1.0.0"
                            IncludeMaximum="yes"/&gt;
        &lt;/Upgrade&gt;

        &lt;!-- Useless but necessary... --&gt;
        &lt;Media Id="1" Cabinet="MyCompany.cab" EmbedCab="yes" /&gt;

        &lt;!-- Precondition: .NET 2 must be installed --&gt;
        &lt;Condition Message='This setup requires the .NET Framework 2 or higher.'&gt;
            &lt;![CDATA[MsiNetAssemblySupport &gt;= "2.0.50727"]]&gt;
        &lt;/Condition&gt;

        &lt;Directory Id="TARGETDIR"
                   Name="SourceDir"&gt;
            &lt;Directory Id="MyCompany"
                       Name="MyCompany"&gt;
                &lt;Directory Id="INSTALLDIR"
                           Name="Integrat"
                           LongName="MyCompany Integration Framework"&gt;
                    &lt;Component Id="MyCompanyDllComponent"
                               Guid="4f362043-03a0-472d-a84f-896522ce7d2b"
                               DiskId="1"&gt;
                        &lt;File Id="MyCompanyIntegrationDll"
                              Name="IbIntegr.dll"
                              src="..\Build\MyCompany.Integration.dll"
                              Vital="yes"
                              LongName="MyCompany.Integration.dll" /&gt;
                        &lt;File Id="MyCompanyServiceModelDll"
                              Name="IbSerMod.dll"
                              src="..\Build\MyCompany.ServiceModel.dll"
                              Vital="yes"
                              LongName="MyCompany.ServiceModel.dll" /&gt;
                    &lt;/Component&gt;

                    &lt;!-- More components --&gt;
                &lt;/Directory&gt;
            &lt;/Directory&gt;
        &lt;/Directory&gt;

        &lt;Feature Id="MyCompanyProductFeature"
                 Title='MyCompany Integration Framework'
                 Description='The complete package'
                 Display='expand'
                 Level="1"
                 InstallDefault='local'
                 ConfigurableDirectory="INSTALLDIR"&gt;
            &lt;ComponentRef Id="MyCompanyDllComponent" /&gt;
        &lt;/Feature&gt;

        &lt;!-- Task scheduler application. It has to be used as a property --&gt;
        &lt;Property Id="finaltaskexe"
                  Value="MyCompany.Integration.Host.exe" /&gt;
        &lt;Property Id="WIXUI_INSTALLDIR"
                  Value="INSTALLDIR" /&gt;

        &lt;InstallExecuteSequence&gt;
            &lt;!-- command must be executed: MyCompany.Integration.Host.exe /INITIALCONFIG parameters.xml --&gt;
            &lt;Custom Action='PropertyAssign'
                    After='InstallFinalize'&gt;NOT Installed AND NOT PATCHFOUND&lt;/Custom&gt;
            &lt;Custom Action='LaunchFile'
                    After='InstallFinalize'&gt;NOT Installed AND NOT PATCHFOUND&lt;/Custom&gt;

            &lt;RemoveExistingProducts Before='CostInitialize' /&gt;
        &lt;/InstallExecuteSequence&gt;

        &lt;!-- execute comand --&gt;
        &lt;CustomAction Id='PropertyAssign'
                      Property='PathProperty'
            Value='[INSTALLDIR][finaltaskexe]' /&gt;
        &lt;CustomAction Id='LaunchFile'
                      Property='PathProperty'
                      ExeCommand='/INITIALCONFIG "[INSTALLDIR]parameters.xml"'
                      Return='asyncNoWait' /&gt;

        &lt;!-- User interface information --&gt;
        &lt;UIRef Id="WixUI_InstallDir" /&gt;
        &lt;UIRef Id="WixUI_ErrorProgressText" /&gt;
    &lt;/Product&gt;
&lt;/Wix&gt;
</code></pre>

[{'answer_id': 56123, 'author': 'Anthony Williams', 'author_id': 5597, 'author_profile': 'https://Stackoverflow.com/users/5597', 'pm_score': 6, 'selected': True, 'text': '<p>There\'s an example in the WiX tutorial: <a href="https://www.firegiant.com/wix/tutorial/getting-started/where-to-install/" rel="nofollow noreferrer">https://www.firegiant.com/wix/tutorial/getting-started/where-to-install/</a></p>\n\n<pre><code>&lt;Property Id="INSTALLDIR"&gt;\n  &lt;RegistrySearch Id=\'AcmeFoobarRegistry\' Type=\'raw\'\n    Root=\'HKLM\' Key=\'Software\\Acme\\Foobar 1.0\' Name=\'InstallDir\' /&gt;\n&lt;/Property&gt;\n</code></pre>\n\n<p>Of course, you\'ve got to set the registry key as part of the install too. Stick this inside a component that\'s part of the original install:</p>\n\n<pre><code>&lt;RegistryKey\n         Key="Software\\Software\\Acme\\Foobar 1.0"\n         Root="HKLM"&gt;\n  &lt;RegistryValue Id="FoobarRegInstallDir"\n             Type="string"\n             Name="InstallDir"\n             Value="[INSTALLDIR]" /&gt;\n&lt;/RegistryKey&gt; \n</code></pre>\n'}, {'answer_id': 8894372, 'author': 'Serge SB', 'author_id': 1153863, 'author_profile': 'https://Stackoverflow.com/users/1153863', 'pm_score': 3, 'selected': False, 'text': '<p>\'Registry\' is deprecated. Now that part of code should look like this:</p>\n\n<pre><code>&lt;RegistryKey Id="FoobarRegRoot"\n             Action="createAndRemoveOnUninstall"\n             Key="Software\\Software\\Acme\\Foobar 1.0"\n             Root="HKLM"&gt;\n  &lt;RegistryValue Id="FoobarRegInstallDir"\n                 Type="string"\n                 Name="InstallDir"\n                 Value="[INSTALLDIR]" /&gt;\n&lt;/RegistryKey&gt;\n</code></pre>\n'}, {'answer_id': 23121035, 'author': 'Jamie', 'author_id': 645431, 'author_profile': 'https://Stackoverflow.com/users/645431', 'pm_score': 2, 'selected': False, 'text': '<p>You don\'t really need to separate RegistryKey from RegistryValue in a simple case like this.  Also, using HKMU instead of HKLM takes care of it whether you\'re doing a machine or user install.</p>\n\n<pre><code>&lt;RegistryValue\n  Root="HKMU"\n  Key="Software\\[Manufacturer]\\[ProductName]"\n  Name="InstallDir"\n  Type="string"\n  Value="[INSTALLDIR]"\n  KeyPath="yes" /&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/55964', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4683/']