Need help on Inno Setup script - issue in check the jre install

后端 未结 2 420
挽巷
挽巷 2020-12-17 03:19

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

相关标签:
2条回答
  • 2020-12-17 03:58

    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;
    
    0 讨论(0)
  • 2020-12-17 04:02

    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.

    0 讨论(0)
提交回复
热议问题