The following is a batch script (save as *.bat or *.cmd) that can almost run on every Windows Version and the output will be a string that indicates which Win ver you are running on. The principle is to check the version from command “ver” and use “find” to find specific version numbers. Use errorlevel to check if it is 0 then we have a match otherwise check the rest of the possibilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | @echo off ver | find "5.1" > nul if errorlevel = 1 goto next0 if errorlevel = 0 goto xp :next0 ver | find "6.0" > nul if errorlevel = 1 goto next if errorlevel = 0 goto win vista :next ver | find "6.1" if errorlevel = 1 goto next1 if errorlevel = 0 goto win7 :next1 ver | find "6.2" > nul if errorlevel = 1 goto next2 if errorlevel = 0 goto win8 :next2 ver | find "6.3" > nul if errorlevel = 1 goto next3 if errorlevel = 0 goto win8.1 :next3 ver | find "6.3" > nul if errorlevel = 1 goto next4 if errorlevel = 0 goto win8.1 :next4 ver | find "10.0" > nul if errorlevel = 1 goto other if errorlevel = 0 goto win10 :xp echo XP goto :eof :win vista echo Vista goto :eof :win7 echo Win7 goto :eof :win8 echo Win8 goto :eof :win8.1 echo Win8.1 goto :eof :win10 echo Win10 goto :eof :other echo Early Win goto :eof |
@echo off ver | find "5.1" > nul if errorlevel = 1 goto next0 if errorlevel = 0 goto xp :next0 ver | find "6.0" > nul if errorlevel = 1 goto next if errorlevel = 0 goto win vista :next ver | find "6.1" if errorlevel = 1 goto next1 if errorlevel = 0 goto win7 :next1 ver | find "6.2" > nul if errorlevel = 1 goto next2 if errorlevel = 0 goto win8 :next2 ver | find "6.3" > nul if errorlevel = 1 goto next3 if errorlevel = 0 goto win8.1 :next3 ver | find "6.3" > nul if errorlevel = 1 goto next4 if errorlevel = 0 goto win8.1 :next4 ver | find "10.0" > nul if errorlevel = 1 goto other if errorlevel = 0 goto win10 :xp echo XP goto :eof :win vista echo Vista goto :eof :win7 echo Win7 goto :eof :win8 echo Win8 goto :eof :win8.1 echo Win8.1 goto :eof :win10 echo Win10 goto :eof :other echo Early Win goto :eof
The ver gives the following output on my OS:
Microsoft Windows [Version 6.3.9600]
Simple Windows Batch to Print Versions
Below is a simpler implementation using the For to capture and split the output the command ver and store it in a variable %version%.
@echo off for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j if "%version%" == "6.0" echo Windows Vista. if "%version%" == "6.1" echo Windows 7 if "%version%" == "6.2" echo Windows 8 if "%version%" == "6.3" echo Windows 8.1 if "%version%" == "10.0" echo Windows 10.
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
368 wordsloading...
Last Post: Setup 3 - Femtocell Home Signal to Extend Mobile Signal Indoors
Next Post: How to Fix phpBB3.1.5 - General Error for Bots?
SET OS=NONE
wmic os get Caption /value | findstr /c:”2003″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k3
)
wmic os get Caption /value | findstr /c:”2008″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k8
)
wmic os get Caption /value | findstr /c:”2012″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k12
)
wmic os get Caption /value | findstr /c:”2016″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k16
)
wmic os get Caption /value | findstr /c:”2019″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k19
)
wmic os get Caption /value | findstr /c:”2022″ > NUL
IF %ERRORLEVEL% == 0 (
SET OS=win2k22
)
Nice. thank you.
Thank you 🙂
Works from XP to newer OS 🙂