【问题标题】:How to create single RegistryKey and refer to it from many RegistryValue's?如何创建单个 RegistryKey 并从许多 RegistryValue 中引用它?
【发布时间】:2013-04-12 21:43:49
【问题描述】:

我创建了一个 RegistryKey 和一个 RegistryValue 嵌套在这个 RegistryKey 中。后来我创建了另一个 RegistryValue - 没有嵌套在 WiX 的 XML 方案中的任何 RegistryKey 中。但我希望这第二个 RegistryValue 实际上在安装完成后位于第一个 RegistryKey 内。所以我想从许多 RegistryValue 中引用一个 RegistryKey。怎么做?

它还要求将各种注册表值放在各种组件中,因此我不能将所有注册表值放在 WiX 方案中的单个注册表项中。

示例如下。

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

现在我必须用与 RegistryKey 的 Key 属性相同的数据填充 ShortcutInstalled RegistryValue 的 Key 属性。但由于重构困难,我不想复制和粘贴它。我只想引用相同的注册表项。获得它的最佳方法是什么?

【问题讨论】:

    标签: wix


    【解决方案1】:

    RegistryKey 元素主要是为了方便您在单个键下嵌套许多 RegistryValue 元素时提供的。但是,没有必要使用RegistryKey 元素,因为RegistryValue 也可以提供完整路径。你上面的例子也可以这样写:

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

    这主要是一个偏好问题。或者,如果您需要在许多 Components 中引用相同的注册表项,那么您可以使用预处理器变量来存储路径的公共部分,然后在许多 RegistryValue 元素中使用它。例如,我们可以将上面的内容修改为:

    <?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>
    

    【讨论】:

    • Rob,但我想对这些值使用相同的键。而且我不会将此键复制并粘贴到许多 RegistryValue 的键属性中(因为很难在各种注册表值处跟踪所有这些属性的更改)。怎么做?
    • WiX 是否有类似引用的机制或类似的机制来规避重构下的问题?
    • 在我的回答中添加了使用预处理器变量来处理这些 cmets 的选项。
    • 谢谢,罗伯!我只是不知道预处理器变量可以包含另一个预处理器变量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2018-03-26
    • 1970-01-01
    • 2015-06-11
    相关资源
    最近更新 更多