Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:13:49+00:00 2026-05-26T09:13:49+00:00

I am looking for a batch file snippet that somehow reads the Windows registry

  • 0

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_MACHINE\SOFTWARE\JavaSoft\Java 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:13:50+00:00Added an answer on May 26, 2026 at 9:13 am

    Ok, I finally figured out the answer. It took a while, and this code is really rough, but it works. If someone wants to improve it, I will award them the answer points:

    @ECHO off
    SET TITLE=detectJDK.bat
    TITLE=%TITLE%
    SETLOCAL ENABLEDELAYEDEXPANSION
    IF EXIST jdkhome.txt (
      ECHO JDK home already set in jdkhome.txt file.
      GOTO :END
    )
    ECHO. 2>merged.txt
    ECHO. 2>list.txt
    ECHO. 2>uniquelist.txt
    IF NOT EXIST reg32.txt ECHO. 2>reg32.txt
    IF NOT EXIST reg64.txt ECHO. 2>reg64.txt
    START /w REGEDIT /e reg32.txt "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\JavaSoft\Java Development Kit"
    TYPE reg32.txt | FIND "JavaHome" > merged.txt
    START /w REGEDIT /e reg64.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit"
    TYPE reg64.txt | FIND "JavaHome" >> merged.txt
    FOR /f "tokens=2 delims==" %%x IN (merged.txt) DO (
      CALL :STRIP "%%~x" >>list.txt
    )
    
    FOR /F "tokens=* delims= " %%a IN (list.txt) DO (
      SET str=%%a
      FIND /I ^"!str!^" list.txt>nul
      FIND /I ^"!str!^" uniquelist.txt>nul
      IF ERRORLEVEL 1 ECHO !str!>>uniquelist.txt
    )
    
    ECHO Select a JDK from the list:
    SET /A COUNT=0
    FOR /f "tokens=1,* delims=" %%y IN (uniquelist.txt) DO (
      SET /A COUNT += 1
      ECHO    !COUNT!: %%~y
    )
    SET /P NUMBER=Type a number here: 
    SET /A COUNT=0
    FOR /f "tokens=1,* delims=" %%z IN (uniquelist.txt) DO (
      SET /A COUNT += 1
      IF !COUNT!==!NUMBER! (
        SET JAVA_HOME=%%~z
      )
    )
    ECHO.
    ECHO JAVA_HOME was found to be %JAVA_HOME%
    ECHO %JAVA_HOME%>jdkhome.txt
    GOTO CLEANUP
    
    :CLEANUP
    DEL /Q merged.txt
    DEL /Q list.txt
    DEL /Q uniquelist.txt
    DEL /Q reg32.txt
    DEL /Q reg64.txt
    GOTO :END
    
    :: Strip quotes and extra backslash from string
    :STRIP
    SET n=%~1
    SET n=%n:\\=\%
    SET n=%n:"=%
    IF NOT "%n%"=="" ECHO %n%
    GOTO :EOF
    
    :END
    FOR /l %%a in (5,-1,1) do (TITLE %TITLE% -- Closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
    :: end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to run a batch file on windows xp professional which creates a
I'm looking at a batch file which defines the following variables: set _SCRIPT_DRIVE=%~d0 set
I am looking for either a batch file or a vbscript that will merge
I am looking to write a batch file that will remove all files from
I've been looking at the SqlPubWiz.exe command to write a batch file so that
Pretty all in question... I'm looking for batch script, code or library which allows
I'm looking for a program to batch decompile Java classes. I found JAD, but
I am looking to create a Windows batch script to move about 2,000 files
I'm looking for a mechanism for suppressing the "Terminate batch job? (Y/N)" invitation that
Looking at creating a simple batch file for my app. My app needs some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.