title: Windows Batch: reg query key value to a variable but do not display error if key doesn't exist
body: <p>I have the following batch command that fetches a registry key and assigns value to a variable but it displays error when the key doesn't exist</p>
  
  <pre><code>for /f "tokens=2,*" %%a in ('reg query HKLM\Software\MySoftware\1.0\MyExecutable /v "InstallDir" ^| findstr InstallDir') do set InstallPath=%%b
  </code></pre>
  
  <p>Is there a way to bypass the exception? I have tried using <strong>2>NUL</strong> after the reg query or at the end of the command but I get an exception <strong>2> was unexpected at this time.</strong></p>
  
  <p>help/ guidance much appreciated</p>