I am looking for a batch file snippet that somehow reads the Windows registry and detects which Java JDK is on a Windows system and then asks the user which one they want to use and remembers the choice.
Here is what I have so far... needs some modifications. This script only finds the first JDK... it doesn t handle multiples.
@echo off
SETLOCAL EnableDelayedExpansion
:: findJDK.bat
start /w regedit /e reg1.txt "HKEY_LOCAL_MACHINESOFTWAREJavaSoftJava Development Kit"
type reg1.txt | find "JavaHome" > reg2.txt
if errorlevel 1 goto ERROR
for /f "tokens=2 delims==" %%x in (reg2.txt) do (
set JavaTemp=%%~x
echo Regedit: JAVA_HOME path : !JavaTemp!
)
if errorlevel 1 goto ERROR
echo.
set JAVA_HOME=%JavaTemp%
set JAVA_HOME=%JAVA_HOME:\=\%
echo JAVA_HOME was found to be %JAVA_HOME%
goto END
:ERROR
echo reg1.txt is: & type reg1.txt
echo reg2.txt is: & type reg2.txt
echo
:END
del reg2.txt
del reg1.txt
pause>nul