Updated JDK version detection, includes detecting microversion (e.g. 1.4.2 instead of 1.4.don't know)

From NSIS Wiki
Jump to navigationJump to search
Author: RobGrant (talk, contrib)


Description

The following will detect the full JDK version in Windows, if it is installed. If you are using pcristip's version of this then you can simply cut and paste this over the top of his function if you wish to have microversion detection. If that functionality doesn't bother you then use his, it's slightly more compact.

$1 will be set to the complete version, while $2 will be set to the root jdk folder path. $3 will be used as well, so don't keep anything useful in it.

The Script

ClearErrors
ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome"
ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "MicroVersion"
StrCpy $1 "$1.$3"
 
IfErrors 0 NoAbort
    MessageBox MB_OK "No Java Development Kit found."       
    Goto Abort
 
NoAbort:
    MessageBox MB_OK "Java Development Kit version $1 found."
 
Abort:
    ; bleh