WIX:从对话框复选框设置注册表值

问题描述

10 多年来第一次使用 Wix,并且第一次使用表单/对话框输入。

一个或多或少像这样定义的属性

<Property Id="THE_FLAG">
  <RegistrySearch Id="SearchTheFlag"  Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)\$(var.SimpleProductName)" Name="the_flag"  Win64="$(var.Win64)" Type="raw" />
</Property>

在表单中有一个控件来设置它:

<Control Id="TheFlagCheckBox" Type="CheckBox" X="45" Y="80" Width="220" Height="17" Property="THE_FLAG" CheckBoxValue="1" Text="Flag for something" />

最后想写:

<RegistryKey Root='HKLM' Key='SOFTWARE\$(var.Manufacturer)\$(var.SimpleProductName)' ForceCreateOnInstall='yes' >
    <RegistryValue Name='the_flag'     Type ='integer' Value='[THE_FLAG]' />
</RegistryKey>

如果我选中该复选框,则会设置注册表值。但是,如果我不选中该复选框,则在运行安装程序时会收到关于无法访问注册表值的警告。我认为这是因为“THE_FLAG”的“值”为空或空字符串。我想避免向用户发出讨厌的警告。我接管了一些代码,之前的所有者使用了所有字符串作为明显的 DWORD 值......也许是为了绕过警告。

如果THE_FLAG的值为“”或null,我可以设置一些条件或将其设置为“0”吗?

解决方法

将以下内容添加到您的创作中:

<SetProperty Id="THE_FLAG" Value="0" Before="InstallInitialize" Sequence="execute">NOT THE_FLAG</SetProperty>

如果在注册表写入完成之前 THE_FLAG 为空(在 MSI 中,null 和空字符串都是空的),这会将 "0" 的值设置为 Before"WriteRegistryValues" 的合理替代值是 .intro-body { width:500px; height:400px; background: linear-gradient(90deg,rgba(8,1,36,0.4),transparent 49%),url('./img/pic.jpg') right / contain repeat-x; filter: brightness(120%) contrast(102%) hue-rotate(342deg) invert(0%) saturate(95%); }