简体   繁体   中英

how to fetch java home directory from registry for windows server system

can any body tell me how to fetch java home directory on windows server system from registry. I have to fetch this for java product version(JRE)

As per Oracle documentation

Oracle Page - Installing the JDK also installs a private JRE and optionally a public copy. The private JRE is required to run the tools included with the JDK. It has no registry settings and is contained entirely in a jre directory (typically at C:\\Program Files\\jdk1.7.0\\jre) whose location is known only to the JDK. On the other hand, the public JRE can be used by other Java applications, is contained outside the JDK (typically at C:\\Program Files\\Java\\jre1.7.0), is registered with the Windows registry (at HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft), can be removed using Add/Remove Programs, might be registered with browsers, and might have the java.exe file copied to the Windows system directory (which would make it the default system Java platform)

For reading a registry key

Link 1 Link 2 Link 3

HI all I use below function to fetch current jre home directory

Private Function GetRegValueJava()
    dim WshShell, strVal,javaCurrVer,javahome
    strVal = ""
    javaCurrVer = "HKLM\Software\JavaSoft\Java Runtime Environment\CurrentVersion"
    Set WshShell = CreateObject("WScript.Shell")
    strVal = WshShell.RegRead(javaCurrVer)
    javahome = "HKLM\Software\JavaSoft\Java Runtime Environment\"&strVal&"\JavaHome"
    GetRegValueJava = WshShell.RegRead(javahome)
    Set WshShell = nothing
End Function

It works Fine for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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