Smi*_*ffy 7 registry checkbox wix
我有一个用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" />
Run Code Online (Sandbox Code Playgroud)
属性定义:
<Property Id="ENABLEHTTPS" value="true">
<RegistrySearch Id="EnableHttpsRegistrySearch" Type="raw" Root="HKLM" Key="SOFTWARE\CompanyName\ProductName" Name="EnableHttps" />
</Property>
Run Code Online (Sandbox Code Playgroud)
该属性将写入注册表:
<Component Id="RegistryEntries">
<RegistryKey Root="HKLM" Key="SOFTWARE\CompanyName\ProductName">
<RegistryValue Name="EnableHttps" Value="[ENABLEHTTPS]" Type="string" />
</RegistryKey>
</Component>
Run Code Online (Sandbox Code Playgroud)
初始安装工作正常.如果选中该复选框,则注册表中的值为"true";如果未选中,则为空.
下次运行安装程序时,例如,要安装新功能,无论注册表设置中的值如何,都始终选中该复选框.
如果我从属性定义中删除默认值,以便在第一次运行安装程序时取消选中该复选框,则一切正常.下次运行安装程序时,复选框(和属性)具有来自注册表的正确值.
就像RegistrySearch在注册表值为空时不设置属性一样.
难道我做错了什么?或者有更好的方法吗?
基本上,如果找不到注册表项,则元素将使用默认值,或者为null,这就是您遇到的问题.
请参阅此处的文档:http://wix.sourceforge.net/manual-wix3/wix_xsd_registrysearch.htm
以下是该问题的解决方案:http: //www.mail-archive.com/wix-users@lists.sourceforge.net/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>
Run Code Online (Sandbox Code Playgroud)
这是一个也适用于属性的示例,如果通过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 <> -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 <> -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 <> 0</Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)