3

My program will be installed to a path in registry, which has two different values for single user and all users.

So I'd like to have something like:

<Property Id="MYINSTALLDIR">
    if single user, then <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
    else if ALLUSERS, then <RegistrySearch Id='MyRegistry' Type='raw' Root='HKLM' Key='Software\MyApp\Foo' Name='InstallDir' />
</Property>    

Is this possible?

Deqing
  • 14,098
  • 15
  • 84
  • 131

2 Answers2

2

Perform the two registry searches to two different properties and then use a SetProperty custom action to assign one of the two properties to the real property based on which one has data and which one has a higher priority ( use conditions to drive the execution ).

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Sorry I have very limited knowledge of WiX so don't know if you could detail a little more. For example how do I write this SetProperty custom action? – Deqing Aug 13 '12 at 09:26
1

Finally, it is working now...

With following snippet in wxs file, ALLUSER=1 or 2 can be passed to msiexec to enable HKLM registry search.

<Property Id="INSTALLDIR1">
    <RegistrySearch Id='RegistryCU' Type='raw' Root='HKCU' Key='Software\Foo' Name='InstallDir' />
</Property>

<Property Id="INSTALLDIR2">
    <RegistrySearch Id='RegistryLM' Type='raw' Root='HKLM' Key='Software\Foo' Name='InstallDir' />
</Property>

<CustomAction Id="PerUserInstall"    Property="InstallDir" Value="[INSTALLDIR1]" Execute="immediate" />
<CustomAction Id="PerMachineInstall" Property="InstallDir" Value="[INSTALLDIR2]" Execute="immediate" /> 
<InstallExecuteSequence>
    <Custom Action="PerUserInstall"    After="AppSearch">ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged))</Custom>      
    <Custom Action="PerMachineInstall" After="AppSearch">ALLUSERS=1  OR (ALLUSERS=2 AND Privileged)</Custom>
</InstallExecuteSequence>

In my case, both HKCU and HKLM contain values and they have same priority, so the only way to do is to set property of ALLUSER in command line.

Deqing
  • 14,098
  • 15
  • 84
  • 131
  • Made my day. Was struggling for days to set a variable depending on a registry value and else to default. After reading this inspirational post, it suddenly all made sense and worked. – Florian Straub Aug 04 '21 at 14:22