方法一:
@echo off
for /f 'tokens=2 delims=[' %%Q in ('ver') do for /f 'tokens=2,3 delims=. ' %%R in ('%%Q') do set ver=%%R.%%S
echo %ver%
pause
方法二:
@echo off
for /f 'tokens=1,2 delims=. ' %%Q in ('wmic os get version ^| findstr '[0-9]'') do set ver=%%Q.%%R
echo %ver%
pause
方法二需要WMIC支持,如果你从未运行过WMIC命令,XP上首次运行时会自动安装WMIC,此时识别速度稍慢,第二次以后无此问题,Win7以上无此问题。方法一只需要cmd能正常运行即可。
@echo off
FOR /F "tokens=4 delims=. " %%i in ('ver') do (
if %%i equ 6 Goto :Win7
if %%i equ 10 Goto :Win10
)
:Win7
echo This is Win7
Goto :EOF
:Win10
echo This is Win10
Goto :EOF
setlocal
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
if "%version%" == "10.0" echo Windows 10
if "%version%" == "6.3" echo Windows 8.1
if "%version%" == "6.2" echo Windows 8.
if "%version%" == "6.1" echo Windows 7.
if "%version%" == "6.0" echo Windows Vista.
if "%version%" == "5.2" echo Windows XP (x64).
if "%version%" == "5.1" echo Windows XP.
if "%version%" == "5.0" echo Windows 2000.
if "%version%" == "4.90" echo Windows Me.
if "%version%" == "4.10" echo Windows 98.
if "%version%" == "4.00" echo Windows 95.
if "%version%" == "3.2" echo Windows 3.2.
if "%version%" == "3.11" echo Windows for Workgroups 3.11.
if "%version%" == "3.10" echo Windows 3.1.
if "%version%" == "3.00" echo Windows 3.0.
if "%version%" == "2.11" echo Windows 2.11.
if "%version%" == "2.10" echo Windows 2.10.
if "%version%" == "2.03" echo Windows 2.03.
if "%version%" == "1.04" echo Windows 1.04.
if "%version%" == "1.03" echo Windows 1.03.
if "%version%" == "1.02" echo Windows 1.02.
if "%version%" == "1.01" echo Windows 1.0.
(XP 后面的全当娱乐,实测无效(