The codeblock should help discover the 32-bit version (requires x64.nsh). This can go immediately before StrCpy $R0 "javaw.exe"
😐 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.; 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}
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.