title: For /f and REG QUERY output and parentheses, trying to find JRE home
body: <p>Im trying to write a batch file to find the JRE directory by querying the registry.</p>
  
  <p>I'm using REG QUERY which is returning the following output:</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java RuntimeEnvironment\1.6
  JavaHome    REG_SZ    C:\Program Files (x86)\Java\jre6
  </code></pre>
  
  <p>Im then trying to use FOR /F to return the JavaHome value as below:</p>
  
  <pre><code>FOR /F "usebackq skip=2 tokens=3*" %%B IN (`REG QUERY "%JAVA_VERSION%" /v %JAVA_HOME_NAME% 2^&gt;nul`) DO (
  echo %%B)
  </code></pre>
  
  <p>Problem is this returns only c:\Program Files. At first i thought that's fine I just need the next token as its split on the following space but that doesnt work, so Im assuming it's the parentheses that's the problem.</p>
  
  <p>Question is, how do I succesfully retrieve the java path from the reg query output?</p>