有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

jvm InnoSetup:检测Java是32位还是64位

在InnoSetup中,我运行以下代码:

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

{}和{}都是{}

在命令行中:

> 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返回


共 (2) 个答案

  1. # 1 楼答案

    Inno安装帮助说明:

    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.

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

    此答案显示了如何在注册表中检查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