简体   繁体   English

无法通过 JAVA -8 64 位及更高版本的 NSIS 安装程序在 Win-10 中检查已安装的 Java 版本

[英]Not able to Check installed Java version in Win-10 through NSIS installer for JAVA -8 , 64-bit and above

The installer works fine for Win-7, Win-8,but works weird for Win-10.安装程序适用于 Win-7、Win-8,但适用于 Win-10。 My Java Version Check Function is -我的 Java 版本检查功能是 -

Function checkJavaVersion
${If} ${RunningX64}
    ${registry::Read} "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environmen" "JAVA_HOME" $0 $1
    MessageBox MB_OK "64 bit JAVA Home - $0"
    MessageBox MB_OK "64 bit JAVA Home - $1"

    ${registry::Read} "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" $0 $1
    MessageBox MB_OK "64 bit JRE - $0"
    MessageBox MB_OK "64 bit JRE - $1"
    ${If} $0 == "" 
        ${registry::Read} "HKLM\SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion" $0 $1
        MessageBox MB_OK "64 bit JDK - $0"
        MessageBox MB_OK "64 bit JDK - $1"
    ${EndIf}

    ${registry::Read} "HKLM\SOFTWARE\WOW6432Node\JavaSoft\Java Runtime Environment" "CurrentVersion" $0 $1
    MessageBox MB_OK "32 bit JRE - $0"
    MessageBox MB_OK "32 bit JRE - $1"
    ${If} $0 == "" 
        ${registry::Read} "HKLM\SOFTWARE\WOW6432Node\JavaSoft\Java Development Kit" "CurrentVersion" $0 $1
        MessageBox MB_OK "32 bit JDK - $0"
        MessageBox MB_OK "32 bit JDK - $1"
    ${EndIf}

${Else}
    ${registry::Read} "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" $0 $1
    MessageBox MB_OK "32 bit JRE - $0"
    MessageBox MB_OK "32 bit JRE - $1"
${EndIf}
FunctionEnd

after running this sample installer in different systems I have found out that for Win-10(64-bit system) with Java 8 (64- bit) installed it is not able to recognize the JAVA version, not even in elevated mode.在不同系统中运行此示例安装程序后,我发现对于安装了 Java 8(64 位)的 Win-10(64 位系统),它无法识别 JAVA 版本,甚至在提升模式下也无法识别。

Also for Win-10(64- bit system) with JAVA 8(32-bit) installed HKLM\\SOFTWARE\\JavaSoft\\Java Runtime Environment this path redirecting the registry search to HKLM\\SOFTWARE\\WOW6432Node\\JavaSoft\\Java Runtime Environment so in both cases (32 bit & 64 bit Java Version check) Java version is found even in Elevated mode this behaves the same,同样对于安装了 JAVA 8(32 位)的 Win-10(64 位系统) HKLM\\SOFTWARE\\JavaSoft\\Java Runtime Environment此路径将注册表搜索重定向到HKLM\\SOFTWARE\\WOW6432Node\\JavaSoft\\Java Runtime Environment所以在两者中情况(32 位和 64 位 Java 版本检查)即使在 Elevated 模式下也能找到 Java 版本,这行为相同,

Please find the attached result for more detailed result.请查找附件结果以获得更详细的结果。 Java 版本检查行为,在不同的机器上

This open issue NSIS installer issue can be referred for more clarity.为了更清楚,可以参考这个未解决的问题NSIS 安装程序问题

Your 64-bit detection code does not make sense, NSIS defaults to the 32-bit registry view in 32-bit installers.您的 64 位检测代码没有意义,NSIS 在 32 位安装程序中默认为 32 位注册表视图。 WOW6432Node is a reserved name and you should not really use it if possible. WOW6432Node是一个保留名称,如果可能,您不应该真正使用它。 Elevating a installer does not change how registry redirection works.提升安装程序不会改变注册表重定向的工作方式。

It should probably look something like this:它应该看起来像这样:

${If} ${RunningX64}
  SetRegView 64
  ${registry::Read} ... $0 $1
  ...
${EndIf}
SetRegView 32
${If} $0 == "" 
  ${registry::Read} ... $0 $1
  ...
${EndIf}

According to the page you linked to, Java v9 changed the registry path and names so you need to update your code to handle those as well.根据您链接到的页面,Java v9 更改了注册表路径和名称,因此您也需要更新代码以处理这些内容。

I resolved this issue by using:我通过使用解决了这个问题:

SetRegView 64

So function which is use for checking is looking like this:因此,用于检查的函数如下所示:

Function LocateJVM
;Check for Java version and location
Push $0
Push $1

ReadRegStr $JAVA_VER HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" CurrentVersion
StrCmp "" "$JAVA_VER" Check64Bit CheckJavaVer

Check64Bit:
    SetRegView 64
    ReadRegStr $JAVA_VER HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" CurrentVersion
    StrCmp "" "$JAVA_VER" JavaNotPresent CheckJavaVer

JavaNotPresent:
    StrCpy $JAVA_INSTALLATION_MSG "Java Runtime Environment nije instalirana na Vašem računaru. Da bi ste pokrenuli ovaj program potrebno je da instalirate Java 1.7 ili noviju."
    Pop $1
    Pop $0
    ;MessageBox MB_OK "Molim instalirajte Javu 1.7 ili noviju."

CheckJavaVer:
    ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$JAVA_VER" JavaHome
    GetFullPathName /SHORT $JAVA_HOME "$0"
    StrCpy $0 $JAVA_VER 1 0
    StrCpy $1 $JAVA_VER 1 2
    StrCpy $JAVA_VER "$0$1"
    IntCmp 17 $JAVA_VER FoundCorrectJavaVer FoundCorrectJavaVer JavaVerNotCorrect

FoundCorrectJavaVer:
    IfFileExists "$JAVA_HOME\bin\javaw.exe" 0 JavaNotPresent
    ;MessageBox MB_OK "Found Java: $JAVA_VER at $JAVA_HOME"
    Goto Done

JavaVerNotCorrect:
    ;MessageBox MB_OK "Molim instalirajte Javu 1.7 ili noviju."
    StrCpy $JAVA_INSTALLATION_MSG "Verzija Java Runtime Environment instalirana na Vašem računaru je $JAVA_VER. Da bi ste pokrenuli ovaj program potrebno je da instalirate Java 1.7 ili noviju."

Done:
    Pop $1
    Pop $0

FunctionEnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM