java - InnoSetup : Detect if Java is 32-bit or 64-bit

标签 java jvm inno-setup

在 InnoSetup 中我运行这段代码:

J32 := ShellExec('', 'java', '-d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
J64 := ShellExec('', 'java', '-d64 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);

J32J64 都是True

在命令行中:

> java -d32 -version
Error: This Java instance does not support a 32-bit JVM.
Please install the desired version.

> echo %errorlevel%
1

> java -d64 -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

> echo %errorlevel%
0

为什么 ShellExec() 忽略 Params

我还尝试了 Exec():

// this way
J32 := Exec('java', '-d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
// and this way
J32 := Exec('>', 'java -d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);

它们都返回 Trueec = 1,尽管我有一个 64 位 java。

似乎 ExecShellExec 返回 True 因为它们成功运行 java,但它们不跟踪 java 返回的错误代码。

最佳答案

Inno Setup 帮助说明:

http://www.jrsoftware.org/ishelp/index.php?topic=setup_architecturesinstallin64bitmode

The System32 path returned by the {sys} constant maps to the 64-bit System directory by default when used in the [Dirs], [Files], [InstallDelete], [Run], [UninstallDelete], and [UninstallRun] sections. This is because Setup/Uninstall temporarily disables WOW64 file system redirection [external link] when files/directories are accessed by those sections. Elsewhere, System32 and {sys} map to the 32-bit System directory, as is normal in a 32-bit process.

所以在 [Code] 部分的 64 位模式下,所有内容都是 32 位的。它将执行 32 位 Java,c:\Windows\System32 指向 WOW64 文件夹,即 32 位版本的 System32。

这个答案展示了如何在注册表中检查 Java:

Need help on Inno Setup script - issue in check the jre install

按照该答案,以下代码似乎可以检查是否安装了 64 位 Java 1.7+:

[Code]

function JavaIsMissing(): Boolean;
var 
javaVersionOutput: AnsiString;

begin

result := not RegQueryStringValue(HKLM64, 'Software\JavaSoft\Java Runtime Environment',
   'CurrentVersion', javaVersionOutput);
if not result then
   result := CompareStr(javaVersionOutput, '1.7') < 0;
end;

[Run]
Filename: "{tmp}\{#JavaInstaller}"; StatusMsg: "Java Runtime Enviroment not installed on your system. Installing..."; Check: JavaIsMissing

关于java - InnoSetup : Detect if Java is 32-bit or 64-bit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8027816/

相关文章:

java - java中 `InputStream` `DataInputStream`和 `BufferedInputStream`的区别?

JVM异常退出——系统资源的清理

inno-setup - 使用 InnoUnzip 安装后解压缩文件 - 错误 "Invalid prototype"

java - HTMLUnit 认为提交按钮是文本输入

java - 关于子串和递归的问题

java - 日期转换

java - 使用适用于 API v2 的 Dropbox Java SDK 时出现 SSLHandshakeException

Ubuntu Linux 上的 Java 崩溃

inno-setup - 在 Inno Setup 中的组件列表中添加分隔线吗?

inno-setup - 如何将参数传递到 Inno 的文件部分