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

查看:28
本文介绍了如何确定 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_MACHINESOFTWAREJavaSoft"我注意到这仅包含有关 64 位 Java 运行时的信息.

But when checking the registry key "HKEY_LOCAL_MACHINESOFTWAREJavaSoft" 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 (x86)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 FilesJavajre1.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 FilesJavajre1.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_MACHINESOFTWAREJavaSoftJava 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 eg.exe query 在线查询注册表值:

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 eg.exe query to query the registry values in-line:

@ECHO OFF
setlocal

if defined PROGRAMFILES(x86) (set "reg=%windir%SysWOW64
eg") else set "reg=reg"
set "branch=HKLMSoftwareJavaSoftJava 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%in

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

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