ErikD
ErikD

Reputation: 91

Set WIXUI_INSTALLDIR to value from registry or default if that is blank?

I would like to be able to read a value from the registry and use it to set the WIXUI_INSTALLDIR before the dialog is displayed but if the value from the registry is blank I want to use a default folder.

I'm new to wix. I've been reading tutorials, documentation, and questions/answers all day and my head is spinning. I think I'm close but I don't have all the pieces quite put together.

The code compiles and links fine but when I run the msi I get an error right before the browse for folder dialog is displayed the error is code 2819 "Control [3] on dialog [2] needs a property linked to it."

In summary what I want to do is:
Read previous install path from registry into a property named "PREVIOUSINSTALLFOLDER".
If "PREVIOUSINSTALLFOLDER" is blank, set WIXUI_INSTALLDIR to "INSTALLFOLDER" as defined in the Directory section.
If "PREVIOUSINSTALLFOLDER" is not blank set WIXUI_INSTALLDIR to "PREVIOUSINSTALLFOLDER".

What am I doing wrong?

Thanks, Erik

Here's my current code:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="EB907F6C-B193-4A40-BA3C-ADF8C069AF34" Name="LaserVault DMS" Language="1033" Version="10.0.0" Manufacturer="Electronic Storage Corp." UpgradeCode="43291cbc-3f74-44ba-ba14-31181bb654bf">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Keywords="LaserVault DMS Server" Description="LaserVault DMS Server" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />
<UIRef Id="WixUI_InstallDir"/>

<Property Id="PREVIOUSINSTALLFOLDER">
  <RegistrySearch Id="PreviousInstallDir" Root="HKLM" Key="Software\ESC" Name="LVDMSPath" Type="raw"></RegistrySearch>
</Property>

<CustomAction Id="SetToDefault" Property="WIXUI_INSTALLDIR" Value="[INSTALLFOLDER]" Execute="immediate" />
<CustomAction Id="SetToPrevious" Property="WIXUI_INSTALLDIR" Value="[PREVIOUSINSTALLFOLDER]" Execute="immediate" />

<InstallExecuteSequence>
  <Custom Action="SetToDefault" After="AppSearch">PREVIOUSINSTALLDIR=""</Custom>
  <Custom Action="SetToPrevious" After="AppSearch"><![CDATA[PREVIOUSINSTALLDIR <> ""]]></Custom>
</InstallExecuteSequence>

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LaserVault" Name="LaserVault">
    <Directory Id="INSTALLFOLDER" Name="LVDMS" />
  </Directory>
  <Directory Id="ProgramMenuFolder" Name="Programs">
    <Directory Id="ProgramMenuDir" Name="LaserVault DMS" />
  </Directory>
  <Directory Id="DesktopFolder" Name="Desktop" />
</Directory>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Id="LVDMSServerConfig" Guid="D9428A16-ECB1-4373-B876-8CF05E7CE37F">
    <File Id="LVDMSServerConfig" Source="C:\Projects\LVDMS10\LVDMSServerConfig\LVDMSServerConfig\bin\Debug\LVDMSServerConfig.exe" KeyPath="yes" />
  </Component>
  <Component Id="LVDMSCore10" Guid="2E956300-78FC-4AFA-8D5D-A2D07B6CB8AE">
    <File Id="LVDMSCore10" Source="C:\Projects\LVDMS10\LVDMSServerConfig\LVDMSServerConfig\bin\Debug\LVDMSCore10.dll" KeyPath="yes" />
  </Component>
  <Component Id="LVDMSInstallationGuide" Guid="ECA2B30A-54CB-4DE4-A659-B429458BDF3A">
    <File Id="LVDMSInstallationGuide" Source="\\192.168.0.211\development\HelpFiles\LaserVault_DMS_10\LaserVault_DMS_Installation_Guide\LaserVault_DMS_Installation_Guide.pdf" KeyPath="yes" />
  </Component>
</ComponentGroup>

<ComponentGroup Id="Shortcuts" Directory="ProgramMenuDir">
  <Component Id="LVDMSServerConfigShortCut">
    <Shortcut Id="LVDMSServerConfigShortCut" Name="LVDMS Server Config" Description="LaserVault DMS Server Configuration" Target="[#LVDMSServerConfig]" WorkingDirectory="INSTALLFOLDER" />
    <RemoveFolder Id="ProgramMenuDir" On="uninstall"/>
    <RegistryValue Root="HKCU" Key="Software\LaserVault\LVDMS" Name="CurrentVersion" Type="string" Value="[ProductVersion]" KeyPath="yes" />
  </Component>
</ComponentGroup>

<ComponentGroup Id="RegistryEntries">
  <Component Id="RegistryLVDMSPath" Guid="9AE59D2B-EF16-4CAA-8A27-AA5BE00FAA07" Permanent="yes" Directory="TARGETDIR">
    <RegistryKey Root="HKLM" Key="Software\ESC">
      <RegistryValue Type="string" Name="LVDMSPath" Value="[INSTALLFOLDER]"/>
    </RegistryKey>
  </Component>
</ComponentGroup>

<Feature Id="Complete" Title="LaserVault DMS Server" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
  <ComponentGroupRef Id="Shortcuts"/>
  <ComponentGroupRef Id="RegistryEntries"/>
    </Feature>
</Product>

Upvotes: 1

Views: 3270

Answers (2)

Adam B
Adam B

Reputation: 1158

For future reference it's enough to only have the following:

<!-- Determine the directory of a previous installation (if one exists) -->
<Property Id="INSTALLFOLDER">
    <RegistrySearch Id="GetInstallDir" Type="raw" Root="HKLM" Key="Software\ESC" Name="LVDMSPath" />
</Property>
...

<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />

Neither of the custom actions are required.

Upvotes: 2

taffit
taffit

Reputation: 2099

I think you were on the right path. I solved it the following way (basically quite similar as you tried to, just the other way round, i.e. set the default value and overwrite it only if the value was found in the registry) using the following steps:

  • Set WIXUI_INSTALLDIR to the default value as defined by your directory structure:

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    
  • Do a RegistrySearch for your previous installation folder:

        <Property Id="PREVIOUSINSTALLFOLDER">
          <RegistrySearch Id="GetPreviousInstallFolder" Root="HKLM" Key="SOFTWARE\ESC" Name="LVDMSPath" Type="raw" />
        </Property>
    
  • Set INSTALLDIR only if a value was found:

        <CustomAction Id="SetINSTALLDIR"  Property="INSTALLDIR" Value="[PREVIOUSINSTALLFOLDER]" Execute="firstSequence" />
        ...
        <InstallExecuteSequence>
                    <Custom Action="SetINSTALLDIR" After="AppSearch">PREVIOUSINSTALLFOLDER</Custom>
        </InstallExecuteSequence>
        <InstallUISequence>
                    <Custom Action="SetINSTALLDIR" After="AppSearch">PREVIOUSINSTALLFOLDER</Custom>
        </InstallUISequence>
    

Upvotes: 0

Related Questions