Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for winver2.bat

(view source code of winver2.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3.  
  4. FOR /F "tokens=*" %%A IN ('VER') DO SET WinVer=%%A
  5. FOR %%A IN (%WinVer%) DO SET WinVer=%%A
  6. SET WinVer=%WinVer:]=%
  7.  
  8. SETLOCAL ENABLEDELAYEDEXPANSION
  9. :: List of VER output strings found at http://en.wikipedia.org/wiki/Ver_(command)
  10. SET 4.=Windows NT 4
  11. SET 5.00.=Windows 2000
  12. SET 5.1.=Windows XP
  13. SET 5.2.=Windows Server 2003
  14. SET 6.0.6001=Windows Vista
  15. SET 6.0.6002=Windows Server 2008
  16. SET 6.1.=Windows 7 or Windows Server 2008 R2
  17. FOR /L %%A IN (4,1,6) DO (
  18. 	FOR /F "tokens=1,2 delims==" %%B IN ('SET %%A.') DO (
  19. 		IF %WinVer% GEQ %%B (
  20. 			SET WinVerTxt=%%C
  21. 		)
  22. 	)
  23. )
  24.  
  25. SET Match=0
  26. IF NOT "%~1"=="" (
  27. 	SET Threshold=
  28. 	FOR %%A IN (NT NT4 "NT 4" 2000 2K W2K XP 2003 2K3 W2K3 Vista 2008 2K8 W2K8 7 2008R2 "2008 R2" 2K8R2 "2K8 R2" W2K8R2 "W2K8 R2") DO (
  29. 		IF /I "%~1"=="%%~A" (
  30. 			SET Threshold=%~1
  31. 		)
  32. 	)
  33.  
  34. 	IF "!Threshold!"=="" (
  35. 		ENDLOCAL
  36. 		GOTO Syntax
  37. 	)
  38.  
  39. 	FOR %%A IN (NT NT4 "NT 4") DO (
  40. 		IF /I "!Threshold!"=="%%~A" (
  41. 			SET Threshold=4.
  42. 		)
  43. 	)
  44. 	FOR %%A IN (2000 2K W2K) DO (
  45. 		IF /I "!Threshold!"=="%%~A" (
  46. 			SET Threshold=5.00.
  47. 		)
  48. 	)
  49. 	IF /I "!Threshold!"=="XP" (
  50. 		SET Threshold=5.1.
  51. 	)
  52. 	FOR %%A IN (2003 2K3 W2K3) DO (
  53. 		IF /I "!Threshold!"=="%%~A" (
  54. 			SET Threshold=5.2.
  55. 		)
  56. 	)
  57. 	IF /I "!Threshold!"=="Vista" (
  58. 		SET Threshold=6.0.6001
  59. 	)
  60. 	FOR %%A IN (2008 2K8 W2K8) DO (
  61. 		IF /I "!Threshold!"=="%%~A" (
  62. 			SET Threshold=6.0.6002
  63. 		)
  64. 	)
  65. 	FOR %%A IN (7 2008R2 "2008 R2" 2K8R2 "2K8 R2" W2K8R2 "W2K8 R2") DO (
  66. 		IF /I "!Threshold!"=="%%~A" (
  67. 			SET Threshold=6.1.
  68. 		)
  69. 	)
  70. 	IF %WinVer% LSS !Threshold! SET Match=1
  71. )
  72. ENDLOCAL & SET WinVerTxt=%WinVerTxt%& EXIT /B %Match%
  73.  
  74.  
  75. :Syntax
  76. ECHO WinVer2.bat,  Version 1.00 for Windows NT 4 and later
  77. ECHO Set the Windows version in 2 environment variables WinVer and WinVertxt,
  78. ECHO and optionally check if it meets the specified minumum required version.
  79. ECHO.
  80. ECHO Usage:   WINVER2  [minver]
  81. ECHO.
  82. ECHO Where:   minver   specifies the minimum required Windows version:
  83. ECHO                   "NT", "NT4", or "NT 4" for Windows NT 4;
  84. ECHO                   "2000", "2K" or "W2K" for Windows 2000;
  85. ECHO                   "XP" for Windows XP; "Vista" for Windows Vista;
  86. ECHO                   "2003", "2K3" or "W2K3" for Windows Server 2003;
  87. ECHO                   "2008", "2K8" or "W2K8" for Windows Server 2008;
  88. ECHO                   "7" for Windows 7;
  89. ECHO                   "2008R2", "2008 R2", "2K8R2", "2K8 R2", "W2K8R2"
  90. ECHO                   or "W2K8 R2" for Windows Server 2008 R2
  91. ECHO.
  92. ECHO Returns: Environment variables WinVer containing the major.minor.build,
  93. ECHO          and WinVerTxt containing the description (e.g. "Windows XP").
  94. ECHO          Return code (errorlevel) 1 if the Windows version does not
  95. ECHO          meet the specified minimum required.
  96. ECHO.
  97. ECHO Written by Rob van der Woude
  98. ECHO http://www.robvanderwoude.com
  99.  
  100. IF "%OS%"=="Windows_NT" COLOR 00
  101.  

page last modified: 2024-04-16; loaded in 0.0061 seconds