Reputation: 521
I created a RegistryKey and a RegistryValue nested inside this RegistryKey. Later I created another RegistryValue - not nested inside whatever RegistryKey in WiX's XML scheme. But I want to this second RegistryValue be inside the first RegistryKey actually after the installation complete. So I want to refer from many RegistryValue's to a single RegistryKey. How to do it?
It also requires that various registry values will be inside various components, so I can't put all the registry values inside a single registry key within the WiX scheme.
The example is presented below.
<Component>
<RegistryValue
Root="HKLM"
Name="ShortcutInstalled"
Key="SetupAndAccessoryData1"
Type="integer"
Value="1"
KeyPath="yes"
/>
</Component>
<Component>
<RegistryKey
Id="SetupAndAccessoryData1"
Action="createAndRemoveOnUninstall"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)\SetupAndAccessoryData"
Root="HKLM"
>
<RegistryValue
Type="string"
Name="InstallDirectory"
Value="[ProductDirectory]"
KeyPath="yes"
>
</RegistryValue>
</RegistryKey>
</Component>
For now I must fill the Key attribute of the ShortcutInstalled RegistryValue with the same data as in the Key attribute at the RegistryKey. But I don't want to copy and paste it because of refactoring difficulties. I just want to refer to the same registry key. What is the best approach to gain it?
Upvotes: 1
Views: 824
Reputation: 35911
The RegistryKey
element is mostly provided for convenience when you have many RegistryValue
elements to nest under a single key. However, it is not necessary to use RegistryKey
element since RegistryValue
can provide the full path as well. Your example above could also be written like:
<Component>
<RegistryValue
Root="HKLM"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)\SetupAndAccessoryData"
Name="ShortcutInstalled"
Value="1"
Type="integer" />
</Component>
<Component>
<RegistryValue
Id="SetupAndAccessoryData1"
Root="HKLM"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)\SetupAndAccessoryData"
Name="InstallDirectory"
Value="[ProductDirectory]"
Type="string" />
</RegistryValue>
</Component>
It's mostly a matter of preference. Alternatively, if you need to refer to the same registry key in many Components
then you could use a preprocessor variable to store the common part of the path, then use it across many RegistryValue
elements. For example, we could modify the above to look like:
<?define CommonReg = "SOFTWARE\$(var.Manufacturer)\$(var.ProductName)\SetupAndAccessoryData" ?>
<Component>
<RegistryValue
Root="HKLM"
Key="$(var.CommonReg)"
Name="ShortcutInstalled"
Value="1"
Type="integer" />
</Component>
<Component>
<RegistryValue
Id="SetupAndAccessoryData1"
Root="HKLM"
Key="$(var.CommonReg)"
Name="InstallDirectory"
Value="[ProductDirectory]"
Type="string" />
</RegistryValue>
</Component>
Upvotes: 3