I am making an installer based on WixUI_Advanced. I am using the solution from here: WiX: How to override "C:\Program Files (x86)" on x64 machine in WixUI_Advanced sequence?
However, I want the installer to remember the previous install directory. Attempting to set the APPLICATIONFOLDER property results in the error "Could not access network location" followed by the directory name. This only happens when a value is actually found in the registry (when upgrading the program).
Here is the relevant code:
<Product Id="*" Name="$(var.ProductName)" Language="1033" Version="$(var.Version)" Manufacturer="OronDF343" UpgradeCode="22187c5e-5fd6-4734-802e-236abd321433">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Description="$(var.ProductName)" />
<PropertyRef Id="NETFRAMEWORK45" />
<Condition Message="This application requires .NET Framework 4.5.1 or later. Please install .NET Framework version 4.5.1 or higher and then run this installer again.">
<![CDATA[Installed OR (NETFRAMEWORK45 >= "#378758")]]>
</Condition>
<MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of $(var.GlobalProductName) is already installed." />
<!-- This is where the problem is. This is how it was implemented in the solution linked above, but I have tried it without the SetDirectory. -->
<Property Id="APPLICATIONFOLDER" Secure="yes">
<RegistrySearch Id="RegistrySearch" Type="raw" Root="HKLM" Win64="$(var.Win64)" Key="Software\$(var.Company)\$(var.ProgID)" Name="InstallLocation" />
</Property>
<SetDirectory Id="APPLICATIONFOLDER" Value="[$(var.PlatformProgramFilesFolder)]$(var.GlobalProductName)">APPLICATIONFOLDER=""</SetDirectory>
<!---->
<MediaTemplate EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop" />
<Directory Id="$(var.PlatformProgramFilesFolder)">
<Directory Id="APPLICATIONFOLDER" Name="$(var.GlobalProductName)">
<Directory Id="skins" Name="skins"/>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="$(var.GlobalProductName)"/>
</Directory>
</Directory>
<Property Id="ApplicationFolderName" Value="$(var.GlobalProductName)" />
<Property Id="WixAppFolder" Value="WixPerMachineFolder" />
<WixVariable Id="WixUISupportPerUser" Value="0" />
<WixVariable Id="WixUILicenseRtf" Value="gpl-3.0.rtf" />
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch $(var.GlobalProductName)" />
<Property Id="WixShellExecTarget" Value="[#$(var.Project.TargetFileName)]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<Feature Id="ProductFeature" Title="$(var.ProductName) Core Files" Level="1" Absent="disallow">
<ComponentRef Id="CreateDirectories" />
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="RegistryStuff" />
</Feature>
<UI>
<UIRef Id="WixUI_Advanced" />
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
</UI>
<!--Hacks for WixUI_Advanced install folder-->
<CustomAction Id="OverwriteWixSetDefaultPerMachineFolder" Property="WixPerMachineFolder" Value="[APPLICATIONFOLDER]" Execute="immediate" />
<CustomAction Id="SetARPINSTALLLOCATION" Property="ARPINSTALLLOCATION" Value="[APPLICATIONFOLDER]" />
<InstallUISequence>
<Custom Action="OverwriteWixSetDefaultPerMachineFolder" After="WixSetDefaultPerMachineFolder" />
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="OverwriteWixSetDefaultPerMachineFolder" After="WixSetDefaultPerMachineFolder" />
<Custom Action="SetARPINSTALLLOCATION" After="InstallValidate"/>
</InstallExecuteSequence>
</Product>
EDIT: I didn't include the code which saves the registry value but it was being saved as '"[APPLICATIONFOLDER]"' and removing the double quotes fixed it for a fresh install. Also forgot brackets in the SetDirectory