WiX:如果特定可执行文件不在 PATH 中,则中止安装

发布于 2025-01-03 02:24:12 字数 458 浏览 1 评论 0原文

我目前正在使用 WiX 打包需要 Java 才能运行的软件。因此,我想在安装过程中检查 java.exe 是否位于 PATH 中,如果找不到则中止。 http://sourceforge.net/mailarchive/message.php?msg_id=23451655<中的解决方案/a> 接近我的需求,但我不想搜索注册表,而是想在 PATH 变量中的目录中查找依赖项。

使用 WiX 可以轻松实现这一点吗?如果没有,是否可以根据自定义操作的返回值设置属性的值。然后,我可以编写一个批处理脚本来查找 Java 并相应地设置 的属性。

I'm currently packaging software with WiX that needs Java to run. Therefore I'd like to check during installation if java.exe is somewhere in the PATH and abort if it could not be found. The solution in http://sourceforge.net/mailarchive/message.php?msg_id=23451655 comes close to my needs, but instead of searching the registry, I'd like to look for the dependency in the directories in the PATH variable.

Is this easily possible with WiX? If not, is it possible to set the value of a property based on the return value of a custom action. I could then write a batch script that looks for Java and sets the property for the <Condition> accordingly.

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

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

发布评论

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

评论(2

淡忘如思 2025-01-10 02:24:14

根据 Yan 的回答,我已经实现了这样的功能:

我的 WiX 源包含:

<Binary Id="B.CustomActionsScript" SourceFile="CustomActions.js" />
<CustomAction
    Id="CA.runJava"
    BinaryKey="B.CustomActionsScript"
    JScriptCall="runJava"
    Execute="immediate"
    Return="check" />

<Condition Message="The Java Runtime Environment is not installed.">
  Installed OR JAVA_IS_INSTALLED
</Condition>

<InstallUISequence>
  <Custom Action="CA.runJava" Before="LaunchConditions">NOT Installed</Custom>
</InstallUISequence>

<InstallExecuteSequence>
  <Custom Action="CA.runJava" Before="LaunchConditions">NOT Installed</Custom>
</InstallExecuteSequence>

并且 CustomActions.js 包含此功能:

function runJava() {
  try {
    var shell = new ActiveXObject("WScript.Shell");
    shell.Run("java -version", 0, true);

    Session.Property("JAVA_IS_INSTALLED") = "1";
  } catch (ex) {
  }
  return 1;
}

而不是在PATH 我正在通过尝试执行 Java 来检查 Java 是否已安装。如果 Java 无法执行,Exec 会抛出异常,并且 JAVA_IS_INSTALLED 永远不会设置。

Based on Yan's answer I've implemented this functionality like this:

My WiX source contains:

<Binary Id="B.CustomActionsScript" SourceFile="CustomActions.js" />
<CustomAction
    Id="CA.runJava"
    BinaryKey="B.CustomActionsScript"
    JScriptCall="runJava"
    Execute="immediate"
    Return="check" />

<Condition Message="The Java Runtime Environment is not installed.">
  Installed OR JAVA_IS_INSTALLED
</Condition>

<InstallUISequence>
  <Custom Action="CA.runJava" Before="LaunchConditions">NOT Installed</Custom>
</InstallUISequence>

<InstallExecuteSequence>
  <Custom Action="CA.runJava" Before="LaunchConditions">NOT Installed</Custom>
</InstallExecuteSequence>

And the CustomActions.js contains this function:

function runJava() {
  try {
    var shell = new ActiveXObject("WScript.Shell");
    shell.Run("java -version", 0, true);

    Session.Property("JAVA_IS_INSTALLED") = "1";
  } catch (ex) {
  }
  return 1;
}

Instead of looking for java.exe in the PATH I'm checking if Java is installed by trying to execute it. If Java cannot be executed Exec throws an exception and JAVA_IS_INSTALLED is never set.

赠我空喜 2025-01-10 02:24:13

我将编写一个立即自定义操作,该操作将执行以下操作:

  • 获取 PATH 环境变量的值。您可以使用 [%PATH] 语法
  • 通过 ; 拆分来解析它,迭代并查找有问题的目录
  • 检查该目录是否存在以及 java.exe 存在,
  • 如果存在,请将 JAVA_IS_INSTALLED 属性设置为 1,否则根本不设置。这可以通过使用 DTF(WiX 工具集提供的框架)的 session["JAVA_IS_INSTALLED"] = 1 来完成,
  • 添加 元素以及 JAVA_IS_INSTALLED< /code> 属性

注意:自定义操作应在 LaunchConditions 操作之前安排,并且应驻留在两个序列中(InstallUISequence 和 InstallExecuteSequence)

I would author an immediate custom action which would do the following:

  • grab the value of PATH environment variable. You can use the [%PATH] syntax
  • parse it by splitting by ;, iterating and finding the directory in question
  • check whether the directory is there and java.exe is present there
  • set JAVA_IS_INSTALLED property to 1 in case it is there, otherwise don't set at all. This can be done as session["JAVA_IS_INSTALLED"] = 1 with DTF (a framework supplied with WiX Toolset)
  • add a <Condition> element with JAVA_IS_INSTALLED property

NOTE: the custom action should be scheduled before LaunchConditions action and should reside in both sequences (InstallUISequence and InstallExecuteSequence)

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