Check Java is present before installing

后端 未结 7 1412
傲寒
傲寒 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:15

    I changed your code a little, I think this way newer versions of Java will be supported ;-)

    function InitializeSetup(): Boolean;
    var
     ErrorCode: Integer;
     JavaInstalled : Boolean;
     Result1 : Boolean;
     Versions: TArrayOfString;
     I: Integer;
    begin
     if RegGetSubkeyNames(HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment', 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]) >= 6 ) ) ) then
        begin
         JavaInstalled := true;
        end else
        begin
         JavaInstalled := false;
        end;
       end;
     end else
     begin
      JavaInstalled := false;
     end;
    
    
     //JavaInstalled := RegKeyExists(HKLM,'SOFTWARE\JavaSoft\Java Runtime Environment\1.9');
     if JavaInstalled then
     begin
      Result := true;
     end else
        begin
      Result1 := MsgBox('This tool requires Java Runtime Environment version 1.6 or newer to run. Please download and install the JRE and run this setup again. Do you want to download it now?',
       mbConfirmation, MB_YESNO) = idYes;
      if Result1 = false then
      begin
       Result:=false;
      end else
      begin
       Result:=false;
       ShellExec('open',
        'http://www.java.com/getjava/',
        '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
      end;
        end;
    end;
    
    
    end.
    

提交回复
热议问题