WiX 条件注册表项

Posted

技术标签:

【中文标题】WiX 条件注册表项【英文标题】:WiX Conditional Registry Entries 【发布时间】:2014-01-09 16:49:42 【问题描述】:

我正在处理我的第一个 WiX 项目,我很难让一些注册表项正常工作。

我的要求是,在设置中可以选择将软件安装在台式计算机还是飞机上。由于实际上没有任何方法可以自动检测到它,因此我创建了一个带有一些单选按钮的附加 UI 屏幕。 (这是在一个单独的文件中)

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <UI>
            <Dialog Id="AircraftDesktopDlg_Custom"
                    Width="370"
                    Height="270"
                    Title="!(loc.InstallDirDlg_Title)">
                <Control Type="RadioButtonGroup"
                         Property="InstallType_Prop"
                         Id="InstallType"
                         Width="200"
                         Height="42"
                         X="20"
                         Y="110">
                    <RadioButtonGroup Property="InstallType_Prop">
                        <RadioButton Text="Aircraft"
                                     Height="17"
                                     Value="0"
                                     Width="50"
                                     X="0"
                                     Y="0" />
                        <RadioButton Text="Desktop"
                                     Height="17"
                                     Value="1"
                                     Width="200"
                                     X="0"
                                     Y="20" />
                    </RadioButtonGroup>
                </Control>
            </Dialog>
        </UI>
    </Fragment>
</Wix>

代码清单 1 - 单选按钮

然后,在我的主 Product.wxs 文件中,我有以下内容。

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product>
    <Property Id="InstallType_Prop"
              Value="0"/>
    .
    .
    .
    <DirectoryRef Id="TARGETDIR">
        <Component Id="AircraftRegistryEntries"
                   Guid="E251C37B-2A4F-46D4-8E9F-24C66FB107E9">
            <Condition>InstallType_Prop = 0</Condition>
            <RegistryKey Root="HKLM"
                         Key="Software\Company\Product\v1.0"
                         Action="createAndRemoveOnUninstall">
                <RegistryValue Type="integer"
                               Name="OfflineMode"
                               Value="0"/>
                <RegistryValue Type="integer"
                               Name="Simulator"
                               Value="0"/>
            </RegistryKey>
        </Component>
        <Component Id="DesktopRegistryEntries"
                   Guid="CACDBBB6-BCAA-4B71-92BE-C762325580A3">
            <Condition>InstallType_Prop = 1</Condition>
            <RegistryKey Root="HKLM"
                         Key="Software\Company\Product\v1.0"
                         Action="createAndRemoveOnUninstall">
                <RegistryValue Type="integer"
                               Name="OfflineMode"
                               Value="1"/>
                <RegistryValue Type="integer"
                               Name="Simulator"
                               Value="0"/>
            </RegistryKey>
        </Component>
    </DirectoryRef>
    .
    .
    .
    <Feature Id='Complete'
             Level='1'>
        <ComponentRef Id='AircraftRegistryEntries'/>
        <ComponentRef Id='DesktopRegistryEntries'/>
    </Feature>
</Product>
</Wix>

代码清单 2 - 属性和注册表项

如您所见,单选按钮与 InstallType_Prop 相关联。

我想要完成的是根据选择的单选按钮安装适当的注册表项。我在注册表组件中插入了这些条件,但它们似乎没有做任何事情。

我什至不必这样做 - 如果选择 Desktop,我只需将 OfflineMode 设置为 1,如果选择 Aircraft,则设置为 0。

我现在不知所措,我认为解决方案在于某个自定义操作或评估条件的顺序,但我不完全确定。

感谢任何帮助。

【问题讨论】:

您找到解决方案了吗?我也有类似的问题 【参考方案1】:

IMO 执行此操作的常用方法是将各种组件分组为(例如)两个功能,每种类型的系统一个,然后用户在标准功能树中选择合适的一个。对于注册表项,对于每种类型的安装,您都有一个组件(用于注册表项),一个在一个功能中,另一个在另一个功能中。

【讨论】:

以上是关于WiX 条件注册表项的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 wix 在卸载时编写注册表项

基于用户选择的Wix条件注册表写入

如何从Wix托管引导程序或自定义操作中读取某些注册表项?

WiX:有条件地注册应用程序以在 Windows 启动时启动

带有COM dll和服务的Wix安装程序

在 Wix 中获取生成的 ProductCode 作为变量