5

I am using the below script to install a Java program. I am facing 2 issues with this script. Please let me know if you know the fix to these issues. I really appreciate for your time

  1. JRE check is happening 2 times i.e Starting of the install and end of the install. I wanted the JRE check happen only at starting time of install

  2. I am checking the below windows registry key to check the JRE and this script is not working on all the cases. I mean some times this is working and sometimes failing for 64 bit JRE installs. I am looking a logic to check the registry for all the scenarios (i.e 32bit, 64 bit and in all windows versions)

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Test"
#define MyAppVersion "1.0"
#define MyAppPublisher "Test"
#define MyAppURL "gmail.com"
#define MyAppExeName "abc.exe"
#define MinJRE "1.6"


[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
;(To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{200DC169-9647-4295-91B4-B1D1D8482B82}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={userdocs}\xsxsxs\bvb
DisableDirPage=yes
DefaultGroupName=test
DisableProgramGroupPage=yes
AllowNoIcons=yes
LicenseFile=C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\TemsOfUse.txt
OutputDir=C:\test\test
OutputBaseFilename=test
SetupIconFile=C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Icon\icon.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest


[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Dirs]
Name: "{app}\Graphics"
Name: "{app}\lib"
Name: "{app}\Database"
Name: "{app}\Grades"
Name: "{app}\HelpFiles"
Name: "{app}\images"
Name: "{app}\Scripts"

[Files]

Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\test.exe"; DestDir: "{app}"; Flags: ignoreversion;
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Graphics\*"; DestDir: "{app}\Graphics"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\lib\*"; DestDir: "{app}\lib"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\DataBase\*"; DestDir: "{app}\DataBase"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Grades\*"; DestDir: "{app}\Grades"; Flags: ignoreversion recursesubdirs createallsubdirs


[Icons]
Name: "{group}\test"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:uninstallProgram,test}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

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


[Code]

function installJRE(): Boolean;
   var
   Result1 : Boolean;
   ErrorCode: Integer;
   begin
   Result1 := false;

   Result1 := MsgBox('Java is required to run the program you are trying to install. Please click on Yes button given below to close this installer and be directed to a website were you can download and install Java.',
   mbConfirmation, MB_YESNO) = idYes;
   if Result1 = false then
   begin
   // user can install the Java later also
   Result:=true;
   end else
   begin
   Result:=false;        
   ShellExec('open', 'http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html','','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
  end;
end;


function InitializeSetup(): Boolean;
var 
 jreVersion: String;                            
   begin
   Result := False; 
     if ((RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\JavaSoft\Java Runtime Environment','CurrentVersion'))) then
     begin      
      RegQueryStringValue(HKLM,'Software\JavaSoft\Java Runtime Environment','CurrentVersion',jreVersion);
      if CompareStr(jreVersion,'{#MinJRE}') > 0 then 
      begin      
          Result:=true;
       end else
       begin
        if(installJRE) then
         Result:=true;  
      end;      
       end else
        if(installJRE) then
        Result:=true;
       end;
    end.
TLama
  • 75,147
  • 17
  • 214
  • 392
Partha
  • 51
  • 1
  • 4

2 Answers2

6

Why the InitializeSetup function is called more than once when it's used as a Check function ?

You are using the InitializeSetup event method as a Check function, what causes this method to be called more than once. The first time when the setup is being initialized (as a real event method) and the next time(s) when the Check determines, whether the file entry from the [Run] section should be opened.

Basically, using event methods for Check functions is wrong. You should not even call them manually, simply let them to be fired by the installer application. In your case rather make a function which will just check if JRE is installed and use such function for your Check.

How to get Java SE Runtime Environment version ?

You don't need to run your setup as 64-bit. You can simply read from WOW registry node to get version of 64-bit JRE on 64-bit Windows. I'd try to use something like this:

[Run]
Filename: "{app}\MyApp.exe"; Flags: nowait postinstall skipifsilent; Check: IsJREInstalled

[Code]
#define MinJRE "1.6"
#define WebJRE "http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html"

function IsJREInstalled: Boolean;
var
  JREVersion: string;
begin
  // read JRE version
  Result := RegQueryStringValue(HKLM32, 'Software\JavaSoft\Java Runtime Environment',
    'CurrentVersion', JREVersion);
  // if the previous reading failed and we're on 64-bit Windows, try to read 
  // the JRE version from WOW node
  if not Result and IsWin64 then
    Result := RegQueryStringValue(HKLM64, 'Software\JavaSoft\Java Runtime Environment',
      'CurrentVersion', JREVersion);
  // if the JRE version was read, check if it's at least the minimum one
  if Result then
    Result := CompareStr(JREVersion, '{#MinJRE}') >= 0;
end;

function InitializeSetup: Boolean;
var
  ErrorCode: Integer;
begin
  Result := True;
  // check if JRE is installed; if not, then...
  if not IsJREInstalled then
  begin
    // show a message box and let user to choose if they want to download JRE;
    // if so, go to its download site and exit setup; continue otherwise
    if MsgBox('Java is required. Do you want to download it now ?',
      mbConfirmation, MB_YESNO) = IDYES then
    begin
      Result := False;
      ShellExec('', '{#WebJRE}', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
    end;
  end;
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 2
    Don't use `Wow6432Node` in the key, ever. (Not only is it bad style, this example won't actually work by default.) When you want to access the 64-bit Registry, use `HKLM64`. – Miral Feb 09 '13 at 11:23
  • Further note that this particular implementation will return the version of either the 32-bit JRE or the 64-bit JRE; if both are installed then it will return the 32-bit version only. This may not be what you want, depending on how the final app (or Java-based component) is actually going to get launched. It's trivial to reverse the preferred order of this if that is desired, however. – Miral Feb 10 '13 at 01:23
0

About issue 1, you should remove check:InitializeSetup; from [Run]. InitializeSetup will be called once when the installer starts,

http://www.jrsoftware.org/ishelp/index.php?topic=scriptevents

When you added an extra check it triggers the function once more, which is unnecessary.

About issue 2, JRE x64 should never be detected at all, as your installer will be executed as x86 and has no chance to access x64 section of registry keys. To validate x64 JRE, you need to set ArchitecturesInstallIn64BitMode.

http://www.jrsoftware.org/ishelp/index.php?topic=setup_architecturesinstallin64bitmode

Bitness is a very complicated topic for installer creators, so you need to investigate further about how to properly play with it.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Thanks Lex. It seems 1 issue is resolved, but still I have 2nd issue. I think the flags are not correct in the below line Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}";check:InitializeSetup; Flags: nowait postinstall skipifsilent – Partha Feb 09 '13 at 03:11
  • @Lex, checks are actually performed more than once (depending on a section in which they are used). – TLama Feb 09 '13 at 03:23
  • 1
    @user2056231, don't use event methods for checks, since event menthods are not used to be called manually. Instead make a function like `function InstallJRE: Boolean;` and this function assign to the `Check`. In the `InitializeSetup` event method then call it simply like `Result := IsJREInstalled;`. That will keep the meaning of the event method since you might later want to extend the current `InitializeSetup` event method and you can forget on that it's called also from `Check` for a certain file. – TLama Feb 09 '13 at 03:26
  • Note that you should only use 64-bit install mode if you are installing a 64-bit application. Otherwise just use the appropriate flags or constants when you need to access the other registry. – Miral Feb 09 '13 at 11:24