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;