title: Get Windows version in a batch file
body: <p>I need to get the OS version with a batch file. I 've seen a lot of examples online, many uses something like this code:</p>
  
  <pre><code>@echo off
  
  ver | find "XP" &gt; nul
  if %ERRORLEVEL% == 0 goto ver_xp
  
  if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit
  
  systeminfo | find "OS Name" &gt; %TEMP%\osname.txt
  FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i
  
  echo %vers% | find "Windows 7" &gt; nul
  if %ERRORLEVEL% == 0 goto ver_7
  
  echo %vers% | find "Windows Vista" &gt; nul
  if %ERRORLEVEL% == 0 goto ver_vista
  
  goto warnthenexit
  
  :ver_7
  :Run Windows 7 specific commands here.
  echo Windows 7
  goto exit
  
  :ver_vista
  :Run Windows Vista specific commands here.
  echo Windows Vista
  goto exit
  
  :ver_xp
  :Run Windows XP specific commands here.
  echo Windows XP
  goto exit
  
  :warnthenexit
  echo Machine undetermined.
  
  :exit
  </code></pre>
  
  <p>The problem is when I execute this on Vista or Windows 7 I get the message </p>
  
  <blockquote>
    <p>Machine undetermined</p>
  </blockquote>
  
  <p>Is there any other way to do what I want?</p>