如何从 Inno Setup 安装 JRE? [英] How do I install a JRE from an Inno Setup?

查看:32
本文介绍了如何从 Inno Setup 安装 JRE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Inno Setup(以及另一个应用程序)安装适用于最新平台(x64 或 x86)的 Java 运行时环境.我找到了一些关于如何检测版本和安装(如果正确)并根据我的需要调整它们的脚本示例,但我一直遇到这个问题:

I'm trying to install the most current platform (x64 or x86) appropriate Java Runtime Environment via Inno Setup (along with another application). I've found some script examples for how to detect the version and install if correct and adapted them to my needs but I keep running into this:

无法打开文件path oJREInstall.exe":
CreateProcess 失败:代码 5:
访问被拒绝

Unable to open file "path oJREInstall.exe":
CreateProcess failed: Code 5:
Access Is Denied

这是严格负责安装JRE的代码:

This is the code strictly responsible for installing the JRE:

[Setup]
AppName="JRE Setup"
AppVersion=0.1
DefaultDirName="JRE Setup"

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "jre-8u11-windows-x64.exe"; DestDir: "{tmp}JREInstall.exe"; 
    Check: IsWin64 AND InstallJava();
Source: "jre-8u11-windows-i586.exe"; DestDir: "{tmp}JREInstall.exe"; 
    Check: (NOT IsWin64) AND InstallJava();

[Run]
Filename: "{tmp}JREInstall.exe"; Parameters: "/s"; 
    Flags: nowait postinstall runhidden runascurrentuser; Check: InstallJava()

[Code]

procedure DecodeVersion(verstr: String; var verint: array of Integer);
var
  i,p: Integer; s: string;
begin
  { initialize array }
  verint := [0,0,0,0];
  i := 0;
  while ((Length(verstr) > 0) and (i < 4)) do
  begin
    p := pos ('.', verstr);
    if p > 0 then
    begin
      if p = 1 then s:= '0' else s:= Copy (verstr, 1, p - 1);
      verint[i] := StrToInt(s);
      i := i + 1;
      verstr := Copy (verstr, p+1, Length(verstr));
    end
    else
    begin
      verint[i] := StrToInt (verstr);
      verstr := '';
    end;
  end;
end;

function CompareVersion (ver1, ver2: String) : Integer;
var
  verint1, verint2: array of Integer;
  i: integer;
begin
  SetArrayLength (verint1, 4);
  DecodeVersion (ver1, verint1);

  SetArrayLength (verint2, 4);
  DecodeVersion (ver2, verint2);

  Result := 0; i := 0;
  while ((Result = 0) and ( i < 4 )) do
  begin
    if verint1[i] > verint2[i] then
      Result := 1
    else
      if verint1[i] < verint2[i] then
        Result := -1
      else
        Result := 0;
    i := i + 1;
  end;
end;

function InstallJava() : Boolean;
var
  ErrCode: Integer;
  JVer: String;
  InstallJ: Boolean;
begin
  RegQueryStringValue(
    HKLM, 'SOFTWAREJavaSoftJava Runtime Environment', 'CurrentVersion', JVer);
  InstallJ := true;
  if Length( JVer ) > 0 then
  begin
    if CompareVersion(JVer, '1.8') >= 0 then
    begin
      InstallJ := false;
    end;
  end;
  Result := InstallJ;
end;

在完整的安装脚本中,同样的消息继续出现.如何让 JRE 安装程序从此脚本化安装文件运行?

In the full setup script the same message continues to come up. How can I get the JRE Setup to run from this scripted setup file?

推荐答案

我找到了问题所在:显然,我在使用这些行时弄错了:

I was able to figure out the issue: Evidently I was mistaken in my use of these lines:

Source: "jre-8u11-windows-x64.exe"; DestDir: "{tmp}JREInstall.exe"; Check: IsWin64 AND InstallJava();
Source: "jre-8u11-windows-i586.exe"; DestDir: "{tmp}JREInstall.exe"; Check: (NOT IsWin64) AND InstallJava();

他们应该像这样:

Source: "jre-8u11-windows-x64.exe"; DestDir: "{tmp}"; DestName: "JREInstall.exe"; Check: IsWin64 AND InstallJava();
Source: "jre-8u11-windows-i586.exe"; DestDir: "{tmp}"; DestName: "JREInstall.exe"; Check: (NOT IsWin64) AND InstallJava();

这似乎解决了问题.

还有这一行我错了:

Filename: "{tmp}JREInstall.exe"; Parameters: "/s"; Flags: nowait postinstall runhidden runascurrentuser; Check: InstallJava()

应该是:

Filename: "{tmp}JREInstall.exe"; Parameters: "/s"; Flags: nowait runhidden runascurrentuser; Check: InstallJava()

这是我对这个特定工具的有限经验能够提出的最佳解决方案.我会在有机会时研究 PrepareToInstall 选项,但目前有效.

This is the best solution my limited experience with this particular tool is able to come up with. I will look into the PrepareToInstall option when I have a chance but this works for now.

这篇关于如何从 Inno Setup 安装 JRE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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