Archive: How to get JRE version using NSIS?


How to get JRE version using NSIS?
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
DetailPrint $2

It will display which version only.that is either 1.6 or 1.7.

But i want to display which version jre1.6.that is 1.6.0_33.I need this version.

How to get this version from register key?


You can use string value Java6FamilyVersion which contains exactly 1.6.0_33.


Thanks slappy.yes.its working fine.but the problem occurs following situation:
If i installed two jre versions(like 32,36) then familyverision will display higher versions only(36).but in the same time registry will take 32 version.because regedit view sequence order.so there is a mismatch occur.

How to take specific version of JRE?


I've made a small script a while back that may or may not be of use to you, depending on your final goal. The script checks if the machine has the latest available JRE installed.

OutFile "JREchk.exe"
Caption "JREchk"
RequestExecutionLevel User
!include TextFunc.nsh

Function .onInit
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
IfErrors 0 CheckLatestJRE
SetRegView 64
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
IfErrors 0 CheckLatestJRE
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION|MB_TOPMOST "Java Runtime Environment is not installed.$\nYou will now be taken to the download page." IDOK DlPage IDCANCEL Exit
CheckLatestJRE:
inetc::get /silent "http://java.com/applet/JreCurrentVersion2.txt" "$PLUGINSDIR\JREchk.tmp" /end
Pop $0
StrCmp $0 "OK" +2
MessageBox MB_RETRYCANCEL|MB_ICONSTOP|MB_TOPMOST "Error checking java.com for latest JRE version.$\nMake sure that Internet connection is available." IDRETRY CheckLatestJRE IDCANCEL Exit
FileOpen $R0 "$PLUGINSDIR\JREchk.tmp" "r"
IfErrors VerChkError
FileRead $R0 $0
FileClose $R0
IfErrors VerChkError
StrCmp $0 "" VerChkError
${TrimNewLines} "$0" $0
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$0" "JavaHome"
IfErrors 0 +2
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION|MB_TOPMOST "You do not have the latest version of Java Runtime Environment installed.$\nYou will now be taken to the download page." IDOK DlPage IDCANCEL Exit
MessageBox MB_OK|MB_ICONINFORMATION|MB_TOPMOST "You have the latest version of Java Runtime Environment installed ($0)." IDOK Exit
VerChkError:
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "Unable to check for latest JRE version." IDOK Exit
DlPage:
ExecShell "open" "http://java.com/en/download/index.jsp"
Exit:
Abort
FunctionEnd

Section Blank
SectionEnd

Sorry, I guess I was distracted while reading the thread, it is now clear what you want.
Checking HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_33\JavaHome will tell you if 1.6.0_33 is installed or not, regardless of whether other versions are installed.