title: Reg Query Batch File
body: <p>To summarise what I want to achieve, I want to query 2 keys, if they exist go to end of batch file, if not install Java. </p>
  
  <p>The batch file is installing Java fine, but when testing if I delete the .txt file:</p>
  
  <pre><code>IF exist %windir%\gpologs\jre_1.7.21.x86.txt goto eof ELSE goto Q1
  </code></pre>
  
  <p>The installer still tried to install over the top, even though one of the registry keys exists?</p>
  
  <p>Here is full batch file:</p>
  
  <pre><code>IF exist %windir%\grouppolicylogs\jre_1.7.21.x86.txt goto eof ELSE goto Q1
  
  :Q1 
  Reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86417025FF}" 
  if %ErrorLevel% EQU == 0 goto End ELSE goto Q2
  
  :Q2 
  Reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83217021FF}" 
  if %ErrorLevel% EQU == 0 goto End ELSE goto Install 
  
  :Install 
  msiexec /i "\\servername\SoftwareRep\Java\Java 1.7.0_21 x86\jre1.7.0_21.msi" /qn
  if %ErrorLevel% EQU 0 (
    &gt;&gt;"\\servername\gpolog\jre_1.7.21.x86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Java Runtime 1.7.0_21x86 Installed"
    &gt;&gt;"%windir%\GpoLogs\jre_1.7.21.x86.txt" echo "Java Runtime 1.7.0_21x86 Installed"
  ) else (
    &gt;&gt;"\\servername\gpolog\JavaInstallErrors.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Error trying to install Java 1.7_21x86"
  )
  
  :END 
  </code></pre>
  
  <p>Where am I going wrong?</p>