如何将复选框设置为“未选中"从 msiexec 命令行? [英] How to set a check box to "unchecked" from the msiexec command line?

查看:37
本文介绍了如何将复选框设置为“未选中"从 msiexec 命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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).

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

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!

我看到了此问题的三种解决方案:

I see three solutions to this problem:

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

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

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

推荐答案

这是应该"工作的方式 - 基本上,该属性不存在,直到用户选中复选框,然后才设置"(存在).因此,如果您想在选中复选框时执行自定义操作,请测试该属性是否存在作为运行自定义操作的条件,而不是检查自定义属性设置的值.

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.

这篇关于如何将复选框设置为“未选中"从 msiexec 命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆