Skip to content
⌘ NSIS Forum Archive

Better Java Detection

2 posts

qzind#

Better Java Detection

The A_slightly_better_Java_Launcher example in the Wiki fails to detect a 32-bit Java run-time on a 64-bit machine, which is common considering the amount of users which historically installed 32-bit Java for Chrome/Firefox.

The codeblock should help discover the 32-bit version (requires x64.nsh). This can go immediately before StrCpy $R0 "javaw.exe"

  ; Fall-back to 32-bit registry
${If} ${RunningX64}
ClearErrors
ReadRegStr $R1 HKLM "Software\Wow6432Node\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "Software\Wow6432Node\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound
${EndIf}

😐 However, due to the redirecting of ProgramFiles to ProgramFiles(x86) this still will have problem if the NSIS installer is in 32-bit mode, so some additional 64-bit detection logic is still required. The full source can be viewed here.

I haven't converted this example for generic usage yet, but it should be trivial to remove the variables our code is using and replace them with your own.
Anders#
It would be nice if you could update the wiki. I don't have Java installed so I cannot really look into the ProgramFiles(x86) issue...