title: Get java installed path using batch file?
body: <ul>
  <li>I need to set JAVA_HOME variable using batch script</li>
  <li>Tried below codes, but no use.</li>
  </ul>
  
  <blockquote>
    <p>for /f %%j in ("java.exe") do @echo.%%~dp$PATH:j</p>
  </blockquote>
  
  <p>the above script gives empty</p>
  
  <blockquote>
    <p>FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY
    "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion')
    DO set CurVer=%%B</p>
  </blockquote>
  
  <p>the above script gives 1.6</p>
  
  <blockquote>
    <p>dir java.exe /B /S</p>
  </blockquote>
  
  <p>the above script gives C:\Windows\System32 but actually java installed in C:\Program Files\Java\jdk1.6.0_31</p>
  
  <ul>
  <li>I need to set JAVA_HOME as C:\Program Files\Java\jdk1.6.0_31.</li>
  </ul>
  
  <p>How to get this?</p>