如何确定32BIT Java的位置 [英] How to determine location of 32BIT Java

查看:232
本文介绍了如何确定32BIT Java的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些日子以来,JRE安装在特定于版本的目录[1]中。

Since some days the JRE is installed in a version specific directory [1].

所以我尝试编写DOS批处理或VBS脚本来确定位置最新安装的JRE 8 32位。

So I tried to write a DOS batch or VBS script to determine the location of the latest installed JRE 8 32 bit.

但是当检查注册表项时,
HKEY_LOCAL_MACHINE \ SOFTWARE \ JavaSoft
i注意到这包含只有关于64位Java运行时的信息。

But when checking the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft" i noticed that this contains only information regarding the 64 Bit Java Runtime.

那么任何想法如何通过DOS或vbs确定最新安装的32位Java运行时的位置?这也应该考虑在系统上可以并行安装64位版本。

So any idea how to determine the location of the latest installed 32 Bit Java Runtime via DOS or vbs? This should also consider that a 64 Bit version might be installed in parallel on the system.

另一种选择可能是目录C:\Program Files中的文件搜索( 86)\Java。但是Java Runtime可能没有安装在这个目录中。

An alternative might be a file search in the directory C:\Program Files (x86)\Java. But Java Runtime might not be installed in this directory.

[1] http://www.oracle.com/technetwork/java/javase/8u20-relnotes-2257729.html

JRE安装目录
从JDK 8u20版本开始,JRE将安装在特定于版本的目录中。例如:
C:\Program Files \ Java \ jre1.8.0_20

JRE Installation Directory Starting with JDK 8u20 release, the JRE will be installed in a version specific directory. For example: C:\Program Files\Java\jre1.8.0_20

特定于版本的目录命名是故意的,并不表示JRE安装是静态的。
与早期版本一样,只有在用户传递STATIC = 1选项(通过命令行或配置文件)时才执行静态JRE安装。

The version specific directory naming is intentional and it does not indicate that the JRE install is static. As with the earlier releases, static JRE install is performed only if STATIC=1 option is passed (via command line or config file) by the user.

推荐答案

我发现64位Java运行时安装不会覆盖32位版本的注册表项。如果您使用32位版本的regedit.exe,您将找到属于32位Java运行时环境安装的注册表项。

As I found out the 64 Bit Java Runtime Installation does not override the registry keys of the 32 bit Version. If you use the 32 bit Version of regedit.exe you will find the registry keys which belong to the 32 bit Java Runtime Environment Installation.

因此以下批处理文件应该解决上述问题:

So the following Batch file should solve the above issue:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ECHO OFF
:: Execution on a 64 BIT system?
if defined PROGRAMFILES(x86) (set "REGEDITLOC=%windir%\SysWOW64\") else set "REGEDITLOC="

:: Define local parameters
set "TEMP_FILE_JAVA_REGISTRY_CONTENT=%~dp0java_runtime_environment.reg"

:: Export java Runtime Keys from registry to a temporary file
START /W %REGEDITLOC%REGEDIT /E "%TEMP_FILE_JAVA_REGISTRY_CONTENT%" "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"

:: Determine the install directory of java
FOR /F "tokens=1* delims==" %%A IN ('TYPE "%TEMP_FILE_JAVA_REGISTRY_CONTENT%" ^| FIND "JavaHome"') DO SET JAVA_RUNTIME_HOME=%%B

:: Remove not required chars
SET JAVA_RUNTIME_HOME=%JAVA_RUNTIME_HOME:"=%
SET JAVA_RUNTIME_HOME=%JAVA_RUNTIME_HOME:\\=\%
@echo %JAVA_RUNTIME_HOME%

:: Delete temp file
@del "%TEMP_FILE_JAVA_REGISTRY_CONTENT%" /S /Q > NUL 2>&1
@ECHO ON
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::






来自rojo的贡献:

上面的脚本说明了正确的想法,但导出.reg文件并抓取它可能有点麻烦。以下是相同的想法,但使用%windir%\ syswow64 \ reg.exe查询来在线查询注册表值:

The above script illustrates the correct idea, but exporting a .reg file and scraping it can be a bit cumbersome. Here's the same idea, but using %windir%\syswow64\reg.exe query to query the registry values in-line:

@ECHO OFF
setlocal

if defined PROGRAMFILES(x86) (set "reg=%windir%\SysWOW64\reg") else set "reg=reg"
set "branch=HKLM\Software\JavaSoft\Java Runtime Environment"

for /f "tokens=3" %%v in ('%reg% query "%branch%" /v "CurrentVersion" ^| find "REG_SZ"') do (
    for /f "tokens=2*" %%I in ('%reg% query "%branch%\%%v" /v "JavaHome" ^| find "REG_SZ"') do (
        set "$JAVA=%%J"
    )
)

echo Location of java.exe: %$JAVA%\bin

这篇关于如何确定32BIT Java的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆