(view source code of winver2.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
FOR /F "tokens=*" %%A IN ('VER') DO SET WinVer=%%A
FOR %%A IN (%WinVer%) DO SET WinVer=%%A
SET WinVer=%WinVer:]=%
SETLOCAL ENABLEDELAYEDEXPANSION
:: List of VER output strings found at http://en.wikipedia.org/wiki/Ver_(command)
SET 4.=Windows NT 4
SET 5.00.=Windows 2000
SET 5.1.=Windows XP
SET 5.2.=Windows Server 2003
SET 6.0.6001=Windows Vista
SET 6.0.6002=Windows Server 2008
SET 6.1.=Windows 7 or Windows Server 2008 R2
FOR /L %%A IN (4,1,6) DO (
FOR /F "tokens=1,2 delims==" %%B IN ('SET %%A.') DO (
IF %WinVer% GEQ %%B (
SET WinVerTxt=%%C
)
)
)
SET Match=0
IF NOT "%~1"=="" (
SET Threshold=
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 (
IF /I "%~1"=="%%~A" (
SET Threshold=%~1
)
)
IF "!Threshold!"=="" (
ENDLOCAL
GOTO Syntax
)
FOR %%A IN (NT NT4 "NT 4") DO (
IF /I "!Threshold!"=="%%~A" (
SET Threshold=4.
)
)
FOR %%A IN (2000 2K W2K) DO (
IF /I "!Threshold!"=="%%~A" (
SET Threshold=5.00.
)
)
IF /I "!Threshold!"=="XP" (
SET Threshold=5.1.
)
FOR %%A IN (2003 2K3 W2K3) DO (
IF /I "!Threshold!"=="%%~A" (
SET Threshold=5.2.
)
)
IF /I "!Threshold!"=="Vista" (
SET Threshold=6.0.6001
)
FOR %%A IN (2008 2K8 W2K8) DO (
IF /I "!Threshold!"=="%%~A" (
SET Threshold=6.0.6002
)
)
FOR %%A IN (7 2008R2 "2008 R2" 2K8R2 "2K8 R2" W2K8R2 "W2K8 R2") DO (
IF /I "!Threshold!"=="%%~A" (
SET Threshold=6.1.
)
)
IF %WinVer% LSS !Threshold! SET Match=1
)
ENDLOCAL & SET WinVerTxt=%WinVerTxt%& EXIT /B %Match%
:Syntax
ECHO WinVer2.bat, Version 1.00 for Windows NT 4 and later
ECHO Set the Windows version in 2 environment variables WinVer and WinVertxt,
ECHO and optionally check if it meets the specified minumum required version.
ECHO.
ECHO Usage: WINVER2 [minver]
ECHO.
ECHO Where: minver specifies the minimum required Windows version:
ECHO "NT", "NT4", or "NT 4" for Windows NT 4;
ECHO "2000", "2K" or "W2K" for Windows 2000;
ECHO "XP" for Windows XP; "Vista" for Windows Vista;
ECHO "2003", "2K3" or "W2K3" for Windows Server 2003;
ECHO "2008", "2K8" or "W2K8" for Windows Server 2008;
ECHO "7" for Windows 7;
ECHO "2008R2", "2008 R2", "2K8R2", "2K8 R2", "W2K8R2"
ECHO or "W2K8 R2" for Windows Server 2008 R2
ECHO.
ECHO Returns: Environment variables WinVer containing the major.minor.build,
ECHO and WinVerTxt containing the description (e.g. "Windows XP").
ECHO Return code (errorlevel) 1 if the Windows version does not
ECHO meet the specified minimum required.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" COLOR 00
page last modified: 2024-04-16; loaded in 0.0061 seconds