how to tell what version of windows and/or cmd.exe a batch file is running on


/ Published in: DOS Batch
Save to your folder(s)

built on work by Simon Sheppard, and Joey.


Copy this code and paste it in your HTML
  1. @echo off
  2. :: from http://ss64.org/viewtopic.php?pid=3136#p3136
  3. ::==================================
  4. ::variables
  5. if %PROCESSOR_ARCHITECTURE%==x86 set pro_arch=32 Bit (x86)
  6. if %PROCESSOR_ARCHITECTURE%==AMD64 set pro_arch=64 Bit (AMD64)
  7. if %PROCESSOR_ARCHITECTURE%==IA64 set pro_arch=Itanium 64 Bit (IA64)
  8.  
  9. :Main
  10. call :clean
  11. for /f "tokens=2 delims=[]" %%x in ('ver') do set cmdver=%%x
  12. set cmdver=%cmdver:Version =%
  13. call :parse_cmdver
  14. call :ver%cmdver%
  15. call :Report
  16. goto :End
  17.  
  18.  
  19. :clean
  20. :: Ensure we don't inherit values from previous runs
  21. set _verCmd=
  22. set _verMajor=
  23. set _verMinor=
  24. set _verBuild=
  25. set _verWin=
  26. goto :eof
  27.  
  28. :Parse_cmdver
  29. :: Turn "5.1.2306" string into actionable variables
  30. for /f "tokens=1,2,3* delims=." %%g in ("%cmdver%") do (
  31. set major=%%g
  32. set minor=%%h
  33. set build=%%i
  34. )
  35. goto :eof
  36.  
  37. :Report
  38. echo. CMD version is %cmdver%
  39. echo. which probably means %longver% %pro_arch%
  40. goto :eof
  41.  
  42. :Report2
  43. echo. The numbers are stored in the following variables:
  44. set _ver
  45. goto :eof
  46.  
  47.  
  48. ::Table of version numbers built from
  49. :: http://en.wikipedia.org/wiki/Microsoft_Windows#Timeline_of_releases
  50. :ver1.01
  51. set longver=Windows 1.01
  52. set shortver=Win101
  53. goto :eof
  54.  
  55. :ver2.03
  56. set longver=Windows 2.03
  57. set shortver=Win203
  58. goto :eof
  59.  
  60. :ver2.10
  61. set longver=Windows 2.10
  62. set shortver=Win21
  63. goto :eof
  64.  
  65. :ver2.11
  66. set longver=Windows 2.11
  67. set shortver=Win211
  68. goto :eof
  69.  
  70. :ver3.0
  71. set longver=Windows 3.0
  72. set shortver=Win3
  73. goto :eof
  74.  
  75. :ver3.1
  76. set longver=Windows 3.1, Windows For Workgroups 3.1, or Windows NT 3.1
  77. set shortver=Win31/WFW31/WinNT31
  78. goto :eof
  79.  
  80. :ver3.11
  81. set longver=Windows For Workgroups 3.11
  82. set shortver=WFW311
  83. goto :eof
  84.  
  85. :ver3.2
  86. set longver=Windows 3.2 (released in Simplified Chinese only)
  87. set shortver=Win32ch
  88. goto :eof
  89.  
  90. :ver3.5
  91. set longver=Windows NT 3.5
  92. set shortver=WinNT35
  93. goto :eof
  94.  
  95. :ver3.51
  96. set longver=Windows NT 3.51
  97. set shortver=WinNT351
  98. goto :eof
  99.  
  100. :ver4.0.950
  101. set longver=Windows 95
  102. set shortver=Win95
  103. goto :eof
  104.  
  105. :ver4.0.1381
  106. set longver=Windows NT 4.0
  107. set shortver=WinNT4
  108. goto :eof
  109.  
  110. :ver4.90.3000
  111. set longver=Windows Me
  112. set shortver=WinMe
  113. goto :eof
  114.  
  115. :ver4.10.1998
  116. set longver=Windows 98
  117. set shortver=Win98
  118. goto :eof
  119.  
  120. :ver4.10.2222
  121. set longver=Windows 98 SE
  122. set shortver=Win98SE
  123. goto :eof
  124.  
  125. :ver5.0.2195
  126. set longver=Windows 2000
  127. set shortver=Win2K
  128. goto :eof
  129.  
  130. :ver5.1.2600
  131. set longver=Windows XP or Windows Fundamentals for Legacy PCs
  132. set shortver=WinXP/WinFun
  133. goto :eof
  134.  
  135. :ver5.2.3790
  136. set longver=Windows XP, Windows XP Pro or Windows Server 2003
  137. set shortver=WinXP/WinXP-Pro/Server2003
  138. goto :eof
  139.  
  140. :ver5.2.4500
  141. set longver=Windows Home Server
  142. set shortver=WinHomeServer
  143. goto :eof
  144.  
  145. :ver6.0.6002
  146. set longver=Windows Vista or Windows Server 2008
  147. set shortver=Vista/Server2008
  148. goto :eof
  149.  
  150. :ver6.1.7600
  151. set longver=Windows 7 or Windows Server 2008 R2
  152. set shortver=Win7/Server2008R2
  153. goto :eof
  154.  
  155.  
  156. :End
  157. :: return version to calling shell/script,
  158. :: see http://ss64.com/nt/syntax-functions.html
  159. endlocal & set _verCmd=%cmdver% & set _verMajor=%major% & set _verMinor=%minor% & set _verBuild=%build% & set _verWin=%shortver%
  160. call :Report2 :: comment this line out to suppress extra reporting

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.