Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

windows installer - WIX: Setting a registry value from a dialog checkbox

Using Wix for the first time in 10+ years, and first time with forms/dialog entry.

Have a property defined more or less like this:

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

Have a control in a form to set it:

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

At the end I want to write it:

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

If I select the checkbox, it sets the registry value. However, if I don't check the checkbox, then I get a warning when running the installer about not being able to acces the registry value. I think it is because the "value" of "THE_FLAG" is null or the empty string. I want to avoid the nasty warning to the user. I took over some code, and the previous owner used all strings for obviously DWORD values...maybe to get around the warning.

Can I set some conditionals or set the value of THE_FLAG to "0" if it is "" or null?

question from:https://stackoverflow.com/questions/65897025/wix-setting-a-registry-value-from-a-dialog-checkbox

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the following to your authoring:

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

This will set the value of THE_FLAG to "0" if it's blank (in MSI, null and empty string are both blank) before the registry writes are done. A reasonable alternate value for Before is "WriteRegistryValues".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...