WiX - How do I get different registry keys for all

2019-07-24 08:21发布

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?

2条回答
男人必须洒脱
2楼-- · 2019-07-24 08:29

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 ).

查看更多
相关推荐>>
3楼-- · 2019-07-24 08:38

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.

查看更多
登录 后发表回答