如何将复选框设置为“未选中”从 msiexec 命令行?

发布于 2024-09-05 04:33:29 字数 1045 浏览 2 评论 0原文

我有一个 msi(使用 WIX 编写),它有一个绑定到自定义属性(称为 MY_PROPERTY)的复选框。我想从命令行运行此 msi,并为此属性指定 0(未选中)或 1(选中)。我的脚本将确定适当的值(基于环境)并将该值注入到 msiexec 命令行中。我的命令行看起来像这样:

msiexec /i my_installer.msi MY_PROPERTY=$value

其中 $value 是 1 或 0,具体取决于环境。问题是,无论我在命令行中为 MY_PROPERTY 提供什么值,该复选框始终会被选中(并且该属性将始终设置为 1)。取消选中该复选框的唯一方法是不指定该属性(使其未定义)。应该注意的是,无论 UI 是否显示,都会发生此行为(在上述命令行中添加“/quiet”不会改变此行为)。

这篇msdn帖子似乎表明这是 Windows 安装程序中的一个已知“错误”(或更准确地说,无论编写 msi 的创作系统如何)。建议使用构建后的 msi hack 作为解决方案。我想知道是否有人遇到过这个问题并提出更好的解决方法/解决方案。谢谢!

更新

我看到这个问题的三种解决方案:

  1. 从@Damien,让包装器脚本在其值为 0 时不将属性传递给 msiexec。这使得脚本更加复杂,并且可能会阻止我覆盖检查的值默认为“已选中”的框。
  2. 来自@Michael Urman,添加一个自定义操作,如果该属性的值为零,则清除该属性。这使得 msi 更加复杂,我必须为 UI 中的每个复选框添加这样的自定义操作。
  3. 另一个想法是简单地禁止在我们的 msi 安装程序中使用复选框,而使用单选框或下拉菜单来代替“对/错”问题。虽然这限制了我们安装程序的 UI 选项,但它允许包装器脚本保持简单,并且不需要自定义操作来“破解”属性。

我目前倾向于选项 3,尽管选项 1 可能是我最初问题的最佳答案。有什么想法吗?

I have an msi (authored with WIX) that has a check box bound to a custom property (call it MY_PROPERTY). I would like to run this msi from the command line, specifying 0 (unchecked) or 1 (checked) for this property. My script will determine the appropriate value (based on the environment) and inject that value into the msiexec command line. My command line looks something like this:

msiexec /i my_installer.msi MY_PROPERTY=$value

Where $value is 1 or 0, depending on the environment. The problem is that no matter what value I supply for MY_PROPERTY at the command line, the check box is always checked (and the property will always be set to 1). The only way to make the checkbox unchecked is to not specify the property (leave it undefined). It should be noted that this behavior occurs regardless of whether or not the UI is showing (adding "/quiet" to the above command line doesn't change this behavior).

This msdn post seems to indicate that this is a known "bug" in windows installer (or more accurately, whatever authoring system wrote the msi). A post-build msi hack is proposed as the solution. I'm wondering if anyone has encountered this issue and come up with a better workaround/solution. Thanks!

Update

I see three solutions to this problem:

  1. From @Damien, have the wrapper script not pass the property to msiexec when its value is 0. This makes the script more complex and would probably prevent me from being able to override the value of a check box that defaults to "checked".
  2. From @Michael Urman, add a custom action that clears the property if its value is zero. This makes the msi more complex, and I would have to add such a custom action for every check box in the UI.
  3. Another idea is to simply disallow the use of check boxes in our msi installers, and use radio boxes or drop-downs for "true/false" questions instead. While this restricts the UI options for our installers, it woudl allow the wrapper scripts to remain simple, and does not require custom actions to "hack" the properties.

I'm currently leaning towards option 3, although option 1 is probably the best answer to my original question. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深者入戏 2024-09-12 04:33:29

这就是它“应该”工作的方式 - 基本上,该属性在用户选中复选框之前不存在,然后它被“设置”(存在)。因此,如果您想在选中复选框时执行自定义操作,则可以测试属性是否存在作为运行自定义操作的条件,而不是检查自定义属性设置的值。

我认为从命令行处理此问题的最佳方法就是您已经提到的:如果您希望选中该复选框,请在命令行上指定自定义属性,否则,不要,并且该复选框将不会被选中。

This is how it is "supposed" to work - basically, the property doesn't exist until a user checks the checkbox, then it is "set" (exists). So if you want to do a custom action when a checkbox is checked, you test for the existence of the property as a condition for running the custom action, instead of checking for the value that the custom prop is set to.

I think the best way to handle this from the command line is what you have already mentioned: if you want the checkbox to be selected, specifiy the custom prop on the command line, otherwise, don't and the checkbox will not be selected.

乙白 2024-09-12 04:33:29

正如您所发现的,当属性已定义(非空白)时,复选框为 true(选中);当属性未定义(空白)时,复选框为 false(未选中)。听起来您需要将环境 1 或 0 字符串转换为复选框 true/false,其中 1 或 0 在命令行中传入。尝试使用 set-property 自定义操作将您的属性设置为 {}(空白),条件是属性已为 “0”。在安装 UI 和安装执行序列中尽早安排它。

最新更新:关于需要多个自定义操作来处理多个复选框的问题,您可以选择。您可以创建多个设置属性操作(好处:很容易知道它们在做什么;成本:其中很多),或者您可以创建一个基于代码的自定义操作来遍历 复选框,用于从 0< 转换的属性列表/code> 为空白(好处:一项操作;成本:文档记录不足,自定义代码)。后一种方法的第二个优点是您可以处理不寻常的 Value 设置,例如在选中时应将属性设置为 0 的复选框。

As you've discovered, checkboxes are true (checked) when the property is defined (non-blank) and false (unchecked) when the property is undefined (blank). It sounds like you need to convert an environment 1 or 0 string to a checkbox true/false, where the 1 or 0 is passed in at the command line. Try using a set-property custom action that sets your property to {} (blank) with a condition of when the property is already "0". Schedule it early in both the Install UI and Install Execute sequences.

Late Update: Regarding the need for multiple custom actions to handle this for multiple checkboxes, you have a choice. You can either create multiple set-property actions (benefit: easy to tell what they're doing; cost: many of them), or you can create a single code-based custom action which walks the Checkbox table for a list of properties to convert from 0 to blank (benefit: one action; cost: poorly documented, custom code). A secondary advantage to the latter approach is that you can handle unusual Value settings, such a check box that should set the property to 0 when checked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文