将默认选中的 Wix 复选框值保存到注册表

问题描述 投票:0回答:2

我有一个用 Wix 编写的安装程序。在 UI 向导中,有一个默认处于选中状态的复选框。我想将此复选框的值保存到注册表,以便使用 Rob Mensching 描述的(更简单版本的)“记住属性”模式进行更改、修复和升级。

复选框实现:

<Control Id="httpsCheckBox" Type="CheckBox" CheckBoxValue="true" X="30" Y="119" Width="139" Height="17" Text="Enable HTTPS services" Property="ENABLEHTTPS" />

属性定义:

    <Property Id="ENABLEHTTPS" value="true">
        <RegistrySearch Id="EnableHttpsRegistrySearch" Type="raw" Root="HKLM" Key="SOFTWARE\CompanyName\ProductName" Name="EnableHttps" />
    </Property>

属性被写入注册表:

    <Component Id="RegistryEntries">
        <RegistryKey Root="HKLM" Key="SOFTWARE\CompanyName\ProductName">
            <RegistryValue Name="EnableHttps" Value="[ENABLEHTTPS]" Type="string" />
        </RegistryKey>
    </Component>

初始安装运行良好。如果复选框处于选中状态,则注册表中的值为“true”;如果未选中,则注册表中的值为空。

下次运行安装程序时,例如要安装新功能,无论注册表设置中的值如何,始终都会选中该复选框。

如果我从属性定义中删除默认值,以便在安装程序第一次运行时取消选中该复选框,则一切正常。下次运行安装程序时,复选框(和属性)将具有注册表中的正确值。

这就像如果注册表值为空,RegistrySearch 不会设置该属性。

我做错了什么吗?或者有更好的方法吗?

checkbox wix registry
2个回答
8
投票

基本上,如果注册表项未找到或为空,该元素将使用默认值,这就是您所遇到的情况。

请参阅此处的文档:http://wix.sourceforge.net/manual-wix3/wix_xsd_registrysearch.htm

解决这个问题的方法如下: http://www.mail-archive.com/[电子邮件受保护]/msg32524.html

    <Property Id="ENABLEHTTPS" >
         <RegistrySearch Id="EnableHttpsRegistrySearch" Type="raw" Root="HKLM" Key="SOFTWARE\CompanyName\ProductName" Name="EnableHttps" />
    </Property>

    <CustomAction Id="SetENABLEHTTPS" Property="ENABLEHTTPS" Value="1" Execute="firstSequence" />

    <Control Id="httpsCheckBox" Type="CheckBox" CheckBoxValue="1" X="30" Y="119" Width="139" Height="17" Text="Enable HTTPS services" Property="ENABLEHTTPS" />

    <InstallUISequence>
        <Custom Action="SetENABLEHTTPS" Before="AppSearch">NOT Installed AND NOT OLDERVERSIONDETECTED</Custom>
    </InstallUISequence>
    <InstallExecuteSequence>
        <Custom Action="SetENABLEHTTPS" Before="AppSearch">NOT Installed AND NOT OLDERVERSIONDETECTED</Custom>
    </InstallExecuteSequence> 

7
投票

这是一个也适用于属性的示例,该属性也考虑是否通过 MSI 转换 (MST)、命令行修改默认属性值,或者如果通过组策略设置后该值已存在于注册表中(即每个边缘我能找到的案例!)

<Property Id='MYPROP' Secure="yes" Admin="yes" Value='-1'>
    <RegistrySearch Id='RegSearch_MYPROP' Root="HKLM"
                    Key="SOFTWARE\CompanyName\ProductName" 
                    Name='MYPROP' Type='raw' />
</Property>

<CustomAction Id='MYPROPSaveCmdLine' Property='CMDLINE_MYPROP' 
              Value='[MYPROP]' Execute='firstSequence' />
<CustomAction Id='MYPROPSetFromCmdLine' Property='MYPROP'
              Value='[CMDLINE_MYPROP]' Execute='firstSequence' />
<CustomAction Id='MYPROPClearCheckbox' Property='MYPROP'
              Value='{}' Execute='firstSequence'/>
<CustomAction Id='MYPROPSaveCheckboxOff' Property='MYPROP' Value='0' />
<CustomAction Id='MYPROPSaveCheckboxOn' Property='MYPROP' Value='1' />

<InstallUISequence>
    <Custom Action='MYPROPSaveCmdLine' Before='AppSearch'>MYPROP &lt;&gt; -1</Custom>
    <Custom Action='MYPROPSetFromCmdLine' After='AppSearch'>CMDLINE_MYPROP</Custom>
    <Custom Action='MYPROPClearCheckbox' After ='MYPROPSetFromCmdLine'>MYPROP=0</Custom>
</InstallUISequence>
<InstallExecuteSequence>
    <Custom Action='MYPROPSaveCmdLine' Before='AppSearch'>MYPROP &lt;&gt; -1</Custom>
    <Custom Action='MYPROPSetFromCmdLine' After='AppSearch'>CMDLINE_MYPROP</Custom>
    <Custom Action='MYPROPClearCheckbox' After ='MYPROPSetFromCmdLine'>MYPROP=0</Custom>
    <Custom Action='MYPROPSaveCheckboxOff' Before='InstallInitialize'>Not MYPROP Or MYPROP=0</Custom>
    <Custom Action='MYPROPSaveCheckboxOn' Before='InstallInitialize'>MYPROP And MYPROP &lt;&gt; 0</Custom>
</InstallExecuteSequence>
© www.soinside.com 2019 - 2024. All rights reserved.