2011-02-15 15 views
8

Quiero instalar Java usando un script de NSIS, pero tengo que saber si Java está instalado o no en el sistema (Windows). En base a las claves de registro, ¿cómo podemos verificar si Java está instalado o no?Script de NSIS para la instalación de Java

¿Alguien puede proporcionar un script de NSIS para verificar la instalación de Java en función de las claves de registro?

Respuesta

3

No lo compilé, pero intentaría seguir. Elegí la clave de registro basada en How can I detect the installed Sun JRE on Windows?.

;-------------------------------- 
;Defines 

    !define JavaRegKey 'HKLM "Software\JavaSoft\Java Runtime Environment" ""' 

;-------------------------------- 
;Installer Sections 
Section 'Java Runtime' SecJava 

    SetOutPath '$TEMP' 
    SetOverwrite on 
    File 'c:\<yourdir>\javasetup.exe' 
    ExecWait '$TEMP\javasetup.exe' $0 
    DetailPrint '..Java Runtime Setup exit code = $0' 
    Delete '$TEMP\javasetup.exe' 

SectionEnd 

;-------------------------------- 
; Functions 
Function .onInit 

    ReadRegStr $R0 ${JavaRegKey} 
    StrCmp $R0 "" JavaMissing JavaFound 

    JavaFound: 
    !insertmacro UnselectSection ${SecJava} 
    Goto JavaCheckDone 

    JavaMissing: 
    !insertmacro SelectSection ${SecJava} 

    JavaCheckDone: 

FunctionEnd 
3

El siguiente fragmento de código comprueba si Java está instalado (jre o jdk). Si Java no está instalado, lo instalará. El script también guarda la ruta a Java en una 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 

Creo que también puede poner el código anterior en una función y llamarlo a donde quiera en su secuencia de comandos NSIS.

2

Otro ejemplo con el instalador jre en línea y cheque 64/32 bits

java min versión

!define JRE_VERSION_6 "1.5" 

función de comprobación

Function DetectJRE 
    ;64bit jre und jdk check 
    SetRegView 64 
    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \ 
      "CurrentVersion" 
    ;StrCmp $2 ${JRE_VERSION_6} done 
    ${VersionCompare} $2 ${JRE_VERSION_6} $R0 
    StrCmp $R0 "1" done 

    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" \ 
      "CurrentVersion" 
    ;StrCmp $2 ${JRE_VERSION_6} done 
    ${VersionCompare} $2 ${JRE_VERSION_6} $R0 
    StrCmp $R0 "1" done 

    ;32bit jre und jdk check 
    SetRegView 32 
    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \ 
      "CurrentVersion" 
    ;StrCmp $2 ${JRE_VERSION_6} done 
    ${VersionCompare} $2 ${JRE_VERSION_6} $R0 
    StrCmp $R0 "1" done 

    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" \ 
      "CurrentVersion" 
    ;StrCmp $2 ${JRE_VERSION_6} done 
    ${VersionCompare} $2 ${JRE_VERSION_6} $R0 
    StrCmp $R0 "1" done 


    Call GetJRE 
    done: 
FunctionEnd 

versión comparar

Function VersionCompare 
    !define VersionCompare `!insertmacro VersionCompareCall` 

    !macro VersionCompareCall _VER1 _VER2 _RESULT 
     Push `${_VER1}` 
     Push `${_VER2}` 
     Call VersionCompare 
     Pop ${_RESULT} 
    !macroend 

    Exch $1 
    Exch 
    Exch $0 
    Exch 
    Push $2 
    Push $3 
    Push $4 
    Push $5 
    Push $6 
    Push $7 

    begin: 
    StrCpy $2 -1 
    IntOp $2 $2 + 1 
    StrCpy $3 $0 1 $2 
    StrCmp $3 '' +2 
    StrCmp $3 '.' 0 -3 
    StrCpy $4 $0 $2 
    IntOp $2 $2 + 1 
    StrCpy $0 $0 '' $2 

    StrCpy $2 -1 
    IntOp $2 $2 + 1 
    StrCpy $3 $1 1 $2 
    StrCmp $3 '' +2 
    StrCmp $3 '.' 0 -3 
    StrCpy $5 $1 $2 
    IntOp $2 $2 + 1 
    StrCpy $1 $1 '' $2 

    StrCmp $4$5 '' equal 

    StrCpy $6 -1 
    IntOp $6 $6 + 1 
    StrCpy $3 $4 1 $6 
    StrCmp $3 '0' -2 
    StrCmp $3 '' 0 +2 
    StrCpy $4 0 

    StrCpy $7 -1 
    IntOp $7 $7 + 1 
    StrCpy $3 $5 1 $7 
    StrCmp $3 '0' -2 
    StrCmp $3 '' 0 +2 
    StrCpy $5 0 

    StrCmp $4 0 0 +2 
    StrCmp $5 0 begin newer2 
    StrCmp $5 0 newer1 
    IntCmp $6 $7 0 newer1 newer2 

    StrCpy $4 '1$4' 
    StrCpy $5 '1$5' 
    IntCmp $4 $5 begin newer2 newer1 

    equal: 
    StrCpy $0 0 
    goto end 
    newer1: 
    StrCpy $0 1 
    goto end 
    newer2: 
    StrCpy $0 2 

    end: 
    Pop $7 
    Pop $6 
    Pop $5 
    Pop $4 
    Pop $3 
    Pop $2 
    Pop $1 
    Exch $0 
FunctionEnd 

getJre

Function GetJRE 
    MessageBox MB_YESNO "XXXXXX require at least Java 1.5! Do you want to download and install it now?" IDYES doInstall 

    Abort 
    doInstall: 
    StrCpy $2 "$TEMP\Java Runtime Environment.exe" 
    nsisdl::download /TIMEOUT=30000 ${JRE_URL} $2 
    Pop $R0 ;Get the return value 
     StrCmp $R0 "success" +3 
     MessageBox MB_OK "Download failed: $R0" 
     Quit 
    ExecWait $2 
    Delete $2 

    Call DetectJRE 
FunctionEnd 

si theire es algo que falta que lo encontrará en la página nsis-wiki

Cuestiones relacionadas