Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I need to find the flavor of Windows that is running using a batch file that will run on anything from Windows NT to Windows 7. I'm using a method based on this page with some minor changes.

Systeminfo gives the flavor of Windows that is running. Is there any authoritative list of names that can be returned? If so where would I find the list?

My intention is to do something like:

 winVer=Unknown

 rem NT doesn't have systeminfo
 ver | find "Windows NT" > nul
 if %errorlevel%==0 set winVer=WinNT

 if exist %SystemRoot%\system32\systeminfo.exe (
  for /f "delims=: tokens=2" %%v in ('sysinfo ^| find "OS Name"') do (
   set verStr=%%v
  )
  echo %verStr% | find "Windows XP" > nul
  if %errorlevel%==0 set winVer=WinXP
  echo %verStr% | find "Windows Vista" > nul
  if %errorlevel%==0 set winVer=WinVista
  ... etc
 )

Thanks

share|improve this question
1  
You might want to use wmic os instead of systeminfo which is much faster (and systeminfo probably uses WMI anyway). –  Joey Mar 22 '10 at 10:58
    
@Johannes, thanks for that I'll use wmic instead of systeminfo, it is faster. "wmic os get name" returns the name similar to systeminfo. Note that wmic is apparently part of the standard Windows install after NT. –  WileCau Mar 23 '10 at 3:32

1 Answer 1

Check this thread: http://stackoverflow.com/questions/1792740/how-to-tell-what-version-of-windows-and-or-cmd-exe-a-batch-file-is-running-on

share|improve this answer
    
@Sergey, thanks for the link. Using ver was my first thought but it isn't definitive or consistent enough, e.g. NT returns "Windows NT Version 4.0", XP returns "Microsoft Windows XP [Version 5.1.2600]", Server 2008 returns "Microsoft Windows [Version 6.1.7600]". Using the version number to infer the OS Name can result in ambiguity, e.g. the other thread has results like "Windows Vista or Windows Server 2008". The OS Name from systeminfo tells you exactly which one it is, without the need for interpretation. The link told me about %PROCESSOR_ARCHITECTURE% though, which I also need :) Thanks –  WileCau Mar 23 '10 at 3:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.