NSIS script for java installation

前端 未结 3 1545
自闭症患者
自闭症患者 2020-12-19 04:40

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

3条回答
  •  情歌与酒
    2020-12-19 05:06

    I didn't compile it, but I would try following. I chose registry key based on 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:\\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
    

提交回复
热议问题