Assuming you want to programmatically determine this from a batch file, you can use the reg.exe
tool installed in windows\system32
.
The annoying thing about this tool is that there is no way to return the exit code to it, so you need to suppress its output by redirecting to nowhere. And also generates an ERROR message when the value does not exist.
@echo off rem rem DetectJvmInstalled.cmd rem reg.exe query "HKLM\Software\JavaSoft\Java Runtime Environment" /v "CurrentVersion" > nul 2> nul if errorlevel 1 goto NotInstalled rem Retrieve installed version number. rem The reg.exe output parsing found at http://www.robvanderwoude.com/ntregistry.php set JvmVersion= for /F "tokens=3* delims= " %%A IN ('reg.exe query "HKLM\Software\JavaSoft\Java Runtime Environment" /v "CurrentVersion"') do set JvmVersion=%%A rem if "%JvmVersion%" == "" goto NotInstalled :Installed echo JVM Version = %JvmVersion% exit /b 0 :NotInstalled echo JVM Not installed. exit /b 1
Notes:
- There are two redirects to the
nul
device, one for standard output and one for standard error. - Detection is performed separately from the parsing of the value so as not to display the message
ERROR...
when the value does not exist. - After the
delims=
option, there is a space character (since space is a delimiter). - The batch file returns an error / exit code from zero if it is installed (installed), or 1 if it fails (not installed).
Hope this helps.
source share