[英]InnoSetup: Detect if Java is 32-bit or 64-bit
In InnoSetup I run this code:在 InnoSetup 中,我运行以下代码:
J32 := ShellExec('', 'java', '-d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
J64 := ShellExec('', 'java', '-d64 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
Both J32
and J64
are True
. J32
和J64
都是True
。
In command line:在命令行中:
> 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
Why does ShellExec()
ignore Params
?为什么
ShellExec()
忽略Params
?
I tried Exec()
also:我也试过
Exec()
:
// this way
J32 := Exec('java', '-d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
// and this way
J32 := Exec('>', 'java -d32 -version', '', SW_HIDE, ewWaitUntilTerminated, ec);
They all return True
, and ec = 1
, despite the fact that I have a 64-bit java.它们都返回
True
和ec = 1
,尽管我有一个 64 位 java.lang.
It seems that Exec
and ShellExec
return True
because they succeed to run java
, but they do not track the error code java
returns.似乎
Exec
和ShellExec
返回True
是因为它们成功运行java
,但它们没有跟踪java
返回的错误代码。
The Inno Setup help states: Inno Setup 帮助说明:
http://www.jrsoftware.org/ishelp/index.php?topic=setup_architecturesinstallin64bitmode 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.
在 [Dirs]、[Files]、[InstallDelete]、[Run]、[UninstallDelete] 和 [UninstallRun] 部分中使用时,{sys} 常量返回的 System32 路径默认映射到 64 位系统目录。 This is because Setup/Uninstall temporarily disables WOW64 file system redirection [external link] when files/directories are accessed by those sections.
这是因为当这些部分访问文件/目录时,安装/卸载会暂时禁用 WOW64 文件系统重定向 [外部链接]。 Elsewhere, System32 and {sys} map to the 32-bit System directory, as is normal in a 32-bit process.
在其他地方,System32 和 {sys} 映射到 32 位系统目录,这在 32 位进程中是正常的。
So in 64-bit mode in the [Code] section, everything is 32-bit.所以在 [Code] 部分的 64 位模式下,一切都是 32 位的。 It will execute 32-bit Java and c:\\Windows\\System32 points to the WOW64 folder, ie the 32-bit version of System32.
它将执行 32 位 Java 并且 c:\\Windows\\System32 指向 WOW64 文件夹,即 System32 的 32 位版本。
This answer shows how to check Java in the registry instead:此答案显示了如何在注册表中检查 Java:
Need help on Inno Setup script - issue in check the jre install 需要有关 Inno Setup 脚本的帮助 - 检查 jre 安装的问题
Following that answer, the following code seems to work to check whether 64-bit Java 1.7+ is installed:在该答案之后,以下代码似乎可以检查是否安装了 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
I wanted something I could use across multiple Inno Setup projects, so I wrote a DLL for detecting Java details (home directory, etc.):我想要一些可以在多个 Inno Setup 项目中使用的东西,所以我编写了一个 DLL 来检测 Java 详细信息(主目录等):
https://github.com/Bill-Stewart/JavaInfo https://github.com/Bill-Stewart/JavaInfo
Download from here: https://github.com/Bill-Stewart/JavaInfo/releases从这里下载: https : //github.com/Bill-Stewart/JavaInfo/releases
The download includes a sample Inno Setup .iss
script that demonstrates how to use the DLL functions (including how to check whether 32-bit or 64-bit).下载包括一个示例 Inno Setup
.iss
脚本,该脚本演示了如何使用 DLL 函数(包括如何检查 32 位还是 64 位)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.