小赖子的英国生活和资讯

批处理检测 WINDOWS 版本

阅读 桌面完整版

下面的批处理(扩展名BAT或者CMD) 可以在几乎任何一个WIN操作系统上运行 该脚本会利用 ver 和 find 命令来判断版本号 并给出相应的WIN系统.

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

在我机器 上 ver 命令给出这样的输出 之后就可以用 find 命令寻找相应的版本号 然后用 errorlevel 上一条命令返回值来进行判断 为0的时候表示找到了匹配 否则进行下一个版本的判断.

Microsoft Windows [Version 6.3.9600]

win-batch-script-to-detect-version

英文: https://helloacm.com/windows-batch-script-to-detect-windows-version/

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version