如何从批处理脚本检查Java安装? [英] How to check Java installation from batch script?

查看:275
本文介绍了如何从批处理脚本检查Java安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个批处理脚本来确定是否已安装Java,如果已安装Java,那么在什么路径下? 我觉得它必须与此类似:

I need to write a batch script to find out if Java is installed, and if it is, then under what path? I feel it has to be something similar to this:

for /f %%j in ("java.exe") do (
   set JAVA_HOME=..........
)

但我无法弄清楚.

P.S.它必须使用带有两个空格的路径.就像在程序文件"中安装了Java一样.

P.S. It has to work with path with spaces two. Like if java is installed into "Program Files".

谢谢.

推荐答案

使用reg [.exe],您可以查询系统上安装的可能的JRE候选对象.可能没有,也可能有几个.

Using reg[.exe] you can query possible JRE candidates that are installed on the system. There could be none or could be several.

在测试设置中,在命令外壳中运行:

On a test set-up, running inside the command shell:

reg query "HKLM\Software\JavaSoft\Java Runtime Environment"

我得到三个结果行,其中第一个是 CurrentVersion REG_SZ 1.6

I get three result lines, of which the first is CurrentVersion REG_SZ 1.6

基于此,查询

reg query "HKLM\Software\JavaSoft\Java Runtime Environment\1.6\"

给我JavaHome REG_SZ C:\Program Files\Java\jre6

比扫描文件系统查找Java二进制文件效率更高.

It's much more efficient than scan a file system to find a java binary.

这已在32位Windows XP的虚拟安装下进行了测试.

This was tested under a virtual installation of Windows XP 32-bit.

这篇关于如何从批处理脚本检查Java安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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