title: Installing Software in a batch file based on the prescence of a Registry Key
body: <p>I am trying to install the latest version of some software via a batch file.
  Each version has a unique string value so I would like to install the latest version only if the value in the registry is not of the latest version.</p>
  <p>The following is part of my batch file:</p>
  <pre><code>reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall{731F6BAA-A986-45A4-8936-7C3AAAAA760B} /f 1.3.0.13565 if %ErrorLevel% EQU 0 goto INSTALL if %ErrorLevel% EQU 1 goto END
  </code></pre>
  <p>The issue is that this does not work. The string name is <code>DisplayVersion</code> but if I type in <code>if %DisplayVersion% EQU 1.3.0.13565</code> this doesn't work either. Perhaps I shouldn't be using <code>ErrorLevel</code>? Is it possible to say <code>if DisplayVersion equals to 1.3.0.13565 then GOTO INSTALL else END</code>?</p>
  <p>EDIT:</p>
  <p>My batch file now looks like this:</p>
  <pre><code>@%SystemRoot%\System32\reg.exe Query &quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}&quot; /F &quot;1.3.0.13565&quot; /Reg:32 1&gt; NUL 2&gt;&amp;1 || Exit /B
  
  :INSTALL
  msiexec /x {731F6BAA-A986-45A4-8936-7C3AAAAA760B} /q
  msiexec /i &quot;\\appserve01\share$\Teams\Teams_x64_13028779.msi&quot; ALLUSER=1
  
  :END
  </code></pre>