Check Java is present before installing

后端 未结 7 1342
傲寒
傲寒 2021-01-30 23:46

I\'m creating an Inno Setup installer for a jar app. What I want to do right now is to check if java is present before proceeding with the install. So I only need to be sure the

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 00:16

    More enhancement for the already defined code:

    1. Check for existence of JRE / JDK.
    2. Verify in either 32bit or 64bit view of registry.

    Code:

    function InitializeSetup(): Boolean;
    var
     ErrorCode: Integer;
     JavaInstalled : Boolean;
     ResultMsg : Boolean;
     Versions: TArrayOfString;
     I: Integer;
     regRoot: Integer;
    begin
     // Check which view of registry should be taken:
     regRoot := HKLM
     begin
      if IsWin64 then
      begin
       regRoot := HKLM64
      end;
     end;
     if (RegGetSubkeyNames(regRoot, 'SOFTWARE\JavaSoft\Java Runtime Environment', Versions)) or (RegGetSubkeyNames(regRoot, 'SOFTWARE\JavaSoft\Java Development Kit', Versions)) then
     begin
      for I := 0 to GetArrayLength(Versions)-1 do
       if JavaInstalled = true then
       begin
        //do nothing
       end else
       begin
        if ( Versions[I][2]='.' ) and ( ( StrToInt(Versions[I][1]) > 1 ) or ( ( StrToInt(Versions[I][1]) = 1 ) and ( StrToInt(Versions[I][3]) >= 7 ) ) ) then
        begin
         JavaInstalled := true;
        end else
        begin
         JavaInstalled := false;
        end;
       end;
     end else
     begin
      JavaInstalled := false;
     end;
    
     if JavaInstalled then
     begin
      Result := true;
     end else
        begin
      ResultMsg := MsgBox('Oracle Java v1.7 or newer not found in the system. Java 1.7 or later is required to run this application (can be installed after this installation too). Do you want to continue?',
       mbConfirmation, MB_YESNO) = idYes;
      if ResultMsg = false then
      begin
       Result := false;
      end else
      begin
       Result := true;
       ShellExec('open',
        'http://www.java.com/getjava/',
        '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
      end;
        end;
    end;
    
    end.
    

提交回复
热议问题