WiX Burn - Setting InstallFolder variable based on a condition

Tall Tyke picture Tall Tyke · Dec 12, 2013 · Viewed 7.9k times · Source

I'm using WiX 3.6 ( but could upgrade to 3.8 if necessary ) and have a bootsrapper written in BURN, that's nearly doing everything I need, except this one issue; which I just can't seem to crack.

I have two variables; Product_XYZ and Product_ABC. The first one contains a folder path populated via a registry search ( so it may be blank, if the search didn't find my reg key ) and the other one is hard-coded ( ie "[ProgramFilesFolder]\ABC" ).

I simply (?) want to set the InstallFolder variable ( so that it appears in the UI via the Options button ) to the value in the Product_XYZ variable ( if it's not blank ). If it is blank, I want to set the InstallFolder to the value in Product_ABC.

ie

If Product_XYZ <> "" then
    InstallFolder = [Product_XYZ]
else
    InstallFolder = [Product_ABC]
endif 

but obviously using BURN logic !!

Can anyone please help me ?

Cheers,

Chris.

Answer

Mark Griffiths picture Mark Griffiths · Feb 11, 2014

I had the same need and found a solution by looking at WiX's own bundle:

    <Variable
      Name='InstallFolder'
      Type='string'
      Value='[ProgramFilesFolder]WiX Toolset v$(var.WixMajorMinor)' />
    <util:RegistrySearch
      Id="PreviousInstallFolderSearch"
      Root='HKLM'
      Key='SOFTWARE\Microsoft\Windows Installer XML\$(var.WixMajorMinor)'
      Value='InstallFolder'
      Variable='PreviousInstallFolder' />
    <util:DirectorySearch
      Path='[PreviousInstallFolder]'
      Variable='InstallFolder'
      After='PreviousInstallFolderSearch'
      Condition='PreviousInstallFolder' />

The <Variable/> element defines the default value.

The <util:RegistrySearch/> looks for the registry value (and, if found, saves it in a new variable called PreviousInstallFolder).

The <util:DirectorySearch/> executes only if the registry key was found. It checks that the directory exists and sets InstallFolder if it does.

Note that if the registry value exists, but the directory it specifies does not exist, then the default value will be used instead.