I want to install Java using an NSIS script, but i have to know whether Java is installed or not in the system (Windows). based on the register keys how can we check if Java
The following fragment of code checks if Java is installed (jre or jdk).
If Java is not installed, it will install it.
The script also saves the path to Java in a variable $JavaInstallationPath.
Var JavaInstallationPath
Section "Find Java" FINDJAVA
DetectTry1:
StrCpy $1 "SOFTWARE\JavaSoft\Java Runtime Environment"
StrCpy $2 0
ReadRegStr $2 HKLM "$1" "CurrentVersion"
StrCmp $2 "" DetectTry2 JRE
JRE:
ReadRegStr $5 HKLM "$1\$2" "JavaHome"
StrCmp $5 "" DetectTry2 GetValue
DetectTry2:
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
StrCmp $2 "" NoJava JDK
JDK:
ReadRegStr $5 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$2" "JavaHome"
StrCmp $5 "" NoJava GetValue
GetValue:
StrCpy $JavaInstallationPath $5
Messagebox MB_OK "Javahome value: $JavaInstallationPath"
Goto done
NoJava:
Messagebox MB_OK "No Java installation detected. Installing Java."
# Install Java
ExecWait "$INSTDIR\java\jre-6u26-windows-i586.exe"
Goto DetectTry1
done:
#$JavaInstallationPath should contain the system path to Java
SectionEnd
I think you can also put the above code in a function and call it wherever you like in your NSIS script.