命令如下,保存为bat文件即可,发帖的时候没有找到代码编辑器,只能这样贴出来了 @echo off
setlocal enabledelayedexpansion
systeminfo|findstr /C:"OS 名称" >%tmp%\tmp.txt
for /f "usebackq delims=" %%i in ("%tmp%\tmp.txt") do set OSver=%%i
echo 版本0: %OSver%
set OSver=%OSver:OS 名称:=%
echo 测试1: %OSver%
set OSver=%OSver: =%
echo 测试2: %OSver%
for /f "tokens=*" %%a in ('echo %OSver%^|findstr "10"') do set OsNum = %%a
echo 测试3-查找结果:%OsNum%
for /f "tokens=2 delims=[]" %%Q in ('ver') do for /f "tokens=2-4 delims=. " %%R in ("%%Q") do set "ver=%%R%%S"&set "verbuild=%%T"
::获取显示版本名称,例如22H2、21H2、20H2、2004、1909、1903等
for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "DisplayVersion" 2^>nul') do set "displayversion=%%a"