如何从Inno Setup安装JRE?

我正在尝试通过Inno Setup(以及另一个应用程序)安装最新的平台(x64或x86)合适的Java Runtime

Environment。我找到了一些脚本示例,这些脚本示例说明了如何检测版本并在正确的情况下进行安装并使其适应我的需要,但我一直遇到以下问题:

无法打开文件“ path \ to \ JREInstall.exe”:

CreateProcess失败:代码5:

拒绝访问

这是严格负责安装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, 'SOFTWARE\JavaSoft\Java 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安装程序?

回答:

我能够找出问题所在:很明显,我在使用这些行时弄错了:

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选项,但这暂时有效。

以上是 如何从Inno Setup安装JRE? 的全部内容, 来源链接: utcz.com/qa/415881.html

回到顶部