Windows Batch Script to Detect Windows Version


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]
win-batch-script-to-detect-version Windows Batch Script to Detect Windows Version batch script windows command shell

win-batch-script-to-detect-version

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 words
Last Post: Setup 3 - Femtocell Home Signal to Extend Mobile Signal Indoors
Next Post: How to Fix phpBB3.1.5 - General Error for Bots?

The Permanent URL is: Windows Batch Script to Detect Windows Version

3 Comments

  1. Meyrou
    • Axel

Leave a Reply