How to install JRE from Inno Setup?

I am trying to install the most modern platform (x64 or x86) corresponding to the Java Runtime Environment through Inno Setup (along with another application). I found some examples of the script in order to determine the version and install, if it is correct and adapted to my needs, but I continue to work on this:

Unable to open file "path \ to \ JREInstall.exe":
Error CreateProcess: Code 5:
Access is denied

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, '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; 

In the full setup, the script continues to display the same message. How can I run JRE Setup from this installation script file?

+6
source share
2 answers

I managed to find out the problem: Obviously, I made a mistake in using 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(); 

and they should have been in place:

 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(); 

This seems to have solved the problem.

Also this line I made a mistake in:

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

Must be:

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

This is the best solution by which my limited experience working with this particular tool may arise. I will consider the PrepareToInstall option when I have a chance, but now it works.

+7
source

In accordance with the initial question: “How to install JRE from Inno script?”, And as the best starting solution, I propose a solution that, I think, works more coherently.

I understand that the user wants to install the JRE for his application if the Java runtime is not installed on the target computer, or if its version is lower than required. Well, I suggest using the AfterInstall parameter and slightly changing the distribution order of the distribution files.

First, we sort the files in the [Files] section, first setting the files with the renaming setting.

 Source: "redist\jre-8u121-windows-i586.exe"; DestDir: "{tmp}"; DestName: "JREInstaller.exe";\ Flags: deleteafterinstall; AfterInstall: RunJavaInstaller(); \ Check: (NOT IsWin64) AND InstallJava(); Source: "redist\jre-8u121-windows-x64.exe"; DestDir: "{tmp}"; DestName: "JREInstaller.exe"; \ Flags: deleteafterinstall; AfterInstall: RunJavaInstaller(); \ Check: IsWin64 AND InstallJava(); Source: "Myprog.exe"; DestDir: "{app}"; Flags: ignoreversion 

The next step we must take is to change the [Run] section as follows.

 [Run] Filename: "{app}\{#MyAppExeName}"; \ Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \ Flags: nowait postinstall skipifsilent 

And last but not least, we performed the RunJavaInstaller() section in the [Code] procedure as follows:

 [Code] procedure RunJavaInstaller(); var StatusText: string; ResultCode: Integer; Path, Parameters: string; begin Path := '{tmp}\JREInstaller.exe'; { http://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html#table_config_file_options } Parameters := '/s INSTALL_SILENT=Enable REBOOT=Disable SPONSORS=Disable REMOVEOUTOFDATEJRES=1'; StatusText:= WizardForm.StatusLabel.Caption; WizardForm.StatusLabel.Caption:='Installing the java runtime environment. Wait a moment ...'; WizardForm.ProgressGauge.Style := npbstMarquee; try if not Exec(ExpandConstant(Path), Parameters, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin { we inform the user we couldn't install the JRE } MsgBox('Java runtime environment install failed with error ' + IntToStr(ResultCode) + '. Try installing it manually and try again to install MyProg.', mbError, MB_OK); end; finally WizardForm.StatusLabel.Caption := StatusText; WizardForm.ProgressGauge.Style := npbstNormal; end; end; 

You may need to replace the Enabled value with 1 and Disabled with 0 . > if the Java installer is not working properly. I have not experienced any problems with this. In any case, in the code you have a comment on the Oracle link if you want to take a look.

Finally, since, unfortunately, we cannot get the status of the JRE installation in any way, we show a message and a progress bar so that the user does not feel that the installer hanged himself. To do this, save the state earlier, execute Exec with the ewWaitUntilTerminated flag to wait for this installation to complete before continuing with ours, and we will restore the previous state after the function has finished.

+2
source

Source: https://habr.com/ru/post/972859/


All Articles