0

I'm trying to create an installer that checks to make sure the version of java installed is at least 1.7. I used the basic code from the accepted answer in this post. Then I added a check for 64bit and changed my root key accordingly. There are a bunch of examples of doing this (here, here, as well as later down in the first post)

My computer is 64bit and has both 32 bit java and 64 bit java installed. The 32 bit version is registered in HKLM\SOFTWARE\JavaSoft\Java Runtime Environment and the 64 bit version is registered in HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment. Both versions are 1.8, but to test I changed the 32 bit version key to 1.5.

I know from the message boxes that the script is correctly detecting my laptop as 64 bit, so the regRoot variable should be getting set to HKLM64. However, the second message box displays my current java version as 1.5 and asks if I want to download a newer one. If I run it on a different laptop with only the 64 bit version of java installed, the second message box doesn't even show up and I go straight to the error message. So it's not actually checking the 64 bit location, but the 32 bit location.

I'm sure this is a stupid mistake on my part, but I just can't seem to track it down. If anyone could give me a hand, I would really appreciate it. Thanks.

Here is my code:

function InitializeSetup(): Boolean;
  var
    ErrorCode: Integer;
    JavaVer : String;
    Result1 : Boolean;
    regRoot : Integer;
  begin
    regRoot := HKLM

    begin
      if IsWin64 then
      begin
        MsgBox('Installing in 64-bit mode', mbInformation, MB_OK)
        regRoot := HKLM64
      end;
    end;
    RegQueryStringValue(regRoot, 'SOFTWARE\JavaSoft\Java Runtime Environment', 'CurrentVersion', JavaVer);
    Result := false;
    MsgBox('Java Version Found: ' + JavaVer, mbInformation, MB_OK)
    if Length( JavaVer ) > 0 then
    begin
      if CompareVersion(JavaVer,"1.7.0") >= 0 then
        begin
          Result := true;
        end;
    end;
    if Result = false then
    begin
      Result1 := MsgBox('This tool requires Java Runtime Environment v1.7 (aka Java 7) or newer to run. Please download and install the JRE before trying to run this software' + #13 + #10 + 'Do you want to download it now?',
        mbConfirmation, MB_YESNO) = idYes;
      if Result1 = true then
      begin
        ShellExec('open',
          'http://www.java.com/en/download/manual.jsp#win',
          '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
      end;
      Result := true; // let the user continue with the installation, whether they installed java or not
    end;
  end;
Community
  • 1
  • 1
Michael
  • 141
  • 2
  • 12
  • Your code works for me. I think you just made a mistake. The `HKLM\SOFTWARE\JavaSoft\Java Runtime Environment` is 64-bit key and the `HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment` is 32-bit key, not the other way around, as you claim. So you possibly modified the 64-bit key, not 32-bit key. – Martin Prikryl Nov 21 '16 at 14:31
  • Martin - see, I knew I was doing something stupid. I actually downloaded the incorrect version of java - 32bit when I thought it was 64. To clarify a little on what you said, I found [this](http://stackoverflow.com/questions/8825244/how-do-i-detect-whether-32-bit-java-is-installed-on-x64-windows-only-looking-at) which states that both 32bit java on a 32bit machine and 64bit java on a 64bit machine are registered at `HKLM\Software\JavaSoft`. But 32bit java on a 64bit machine is registered at `HKLM\Software\Wow6432Node\Javasoft`. I guess I need to check both possibilities. – Michael Nov 21 '16 at 20:55
  • RobeN - that's what I tried at first, but the rootpath is actually an integer. Don't understand why – Michael Nov 21 '16 at 20:56

0 Answers0