I need to check that whether java home is available in my system and if java home is not availkable it needs to display an error message and want to check the java version is less than 1.7.If it is greater than 1.7 it needs to display an error.is it possible.Currently i'm using the below script .Can any one suggest What are the changes need to mADe on the script.Or whether any new script needed. Thanks in advance
@echo off
setlocal enableextensions disabledelayedexpansion
:: possible locations under HKLM\SOFTWARE of JavaSoft registry data
set "javaNativeVersion="
set "java32ON64=Wow6432Node\"
:: for variables
:: %%k = HKLM\SOFTWARE subkeys where to search for JavaSoft key
:: %%j = full path of "Java Runtime Environment" key under %%k
:: %%v = current java version
:: %%e = path to java
set "javaDir="
set "javaVersion="
for %%k in ( "%javaNativeVersion%" "%java32ON64%") do if not defined javaDir (
for %%j in (
"HKLM\SOFTWARE\%%~kJavaSoft\Java Runtime Environment"
) do for /f "tokens=3" %%v in (
'reg query "%%~j" /v "CurrentVersion" 2^>nul ^| find /i "CurrentVersion"'
) do for /f "tokens=2,*" %%d in (
'reg query "%%~j\%%v" /v "JavaHome" 2^>nul ^| find /i "JavaHome"'
) do ( set "javaDir=%%~e" & set "javaVersion=%%v" )
)
if not defined javaDir (
echo Java not found
) else (
echo JAVA_HOME="%javaDir%"
echo JAVA_VERSION="%javaVersion%"
)
endlocal
pause
You can use LSS
, GRT
and EQU
and so on to compare string in batch.
EQU
= Equal toNEQ
= Not equal toLSS
= Less thanLEQ
= Less than or equal toGTR
= Greater thanGEQ
= Greater than or equal toSince you have got the version info in %javaVersion%
, what you want is just display the error message.
You can modify you code into:
if not defined javaDir (
echo Java not found
) else (
echo JAVA_HOME="%javaDir%"
echo JAVA_VERSION="%javaVersion%"
if "%javaVersion%" LSS "1.7" (
echo Java version is too low!
goto exit
)
if "%javaVersion%" GTR "1.7" (
echo JAVA version is too high!
goto exit
)
)
:exit
endlocal
pause