2

My program is supposed to be installed to a path that recorded in registry. If the registry key is not found, then install to another(default) path.

For example, I'd like to have something like:

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
    if not found, then set "MYINSTALLDIR" to "D:\working\defaultApps"
</Property>    

How should I write my wxs file to make this happen?

EDIT:

The problem now is:

if not found in registry, then set "MYINSTALLDIR" to LocalAppDataFolder 

I tried

<Property Id="MYINSTALLDIR" Value="LocalAppDataFolder">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
</Property>

But error returned:

Error 1606. Could not access network location LocalAppDataFolder.
Deqing
  • 14,098
  • 15
  • 84
  • 131
  • 1
    See this answer on how to set a property based on a condition: http://stackoverflow.com/questions/1690162/wix-set-a-property-based-on-a-condition – BryanJ Aug 08 '12 at 20:17

2 Answers2

6

Ok, I finally figure out how to do it.

With Custom Action, the default value can now be set to another property:

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
</Property>

<CustomAction Id="UserInstallDir" Property="InstallDir" Value="[INSTALLDIRCU]" Execute="immediate" />
<CustomAction Id="UserInstallDirDefault" Property="InstallDir" Value="[LocalAppDataFolder]" Execute="immediate" />

<InstallExecuteSequence>
    <Custom Action="UserInstallDir" After="AppSearch">MYINSTALLDIR</Custom>      
    <Custom Action="UserInstallDirDefault" After="AppSearch">NOT MYINSTALLDIR</Custom>      
</InstallExecuteSequence>
Deqing
  • 14,098
  • 15
  • 84
  • 131
4

From memory the example below should work. If no value is found for the search, the property gets the default value. It's only overwritten if the search succeeds.

<Property Id="MYINSTALLDIR" Value="Default Property Value">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
</Property>
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
  • I just met problem with your solution. Just edited my question, could you help to have a look? Thx! – Deqing Aug 15 '12 at 05:27