大佬教程收集整理的这篇文章主要介绍了用批处理抓取Windows版本信息,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[1]Python 环境下比较简单,调用platform 模块即可
[2]没有Python 情况下,可以用ver 命令实现。
>ver Microsoft Windows [Version 10.0.16299.967]
<a>自动化用简单的Batch脚本[不推荐]
:: ------------------------------------- :: check Windows Version :: 5.0 = W2000 :: 5.1 = XP :: 5.2 = Server 2003 :: 6.0 = Vista or Server 2008 :: 6.1 = Win7 or Server 2008R2 :: 6.2 = Win8 or Server 2012 :: 6.3 = Win8.1 or Server 2012R2 :: 10.0 = Win10.0,Server 2016 or Server 2019 :: 0.0 = UnkNown or Unable to determine :: -------------------------------------- echo OS Detection: StarTing ver | findstr /i "5\.0\." if %ERRORLEVEL% EQU 0 (echo OS = Windows 2000) ver | findstr /i "5\.1\." if %ERRORLEVEL% EQU 0 (echo OS = Windows Xp) ver | findstr /i "5\.2\." if %ERRORLEVEL% EQU 0 (echo OS = Server 2003) ver | findstr /i "6\.0\." > nul if %ERRORLEVEL% EQU 0 (echo OS = Vista / Server 2008) ver | findstr /i "6\.1\." > nul if %ERRORLEVEL% EQU 0 (echo OS = Windows 7 / Server 2008R2) ver | findstr /i "6\.2\." > nul if %ERRORLEVEL% EQU 0 (echo OS = Windows 8 / Server 2012) ver | findstr /i "6\.3\." > nul if %ERRORLEVEL% EQU 0 (echo OS = Windows 8.1 / Server 2012R2) ver | findstr /i "6\.3\." > nul if %ERRORLEVEL% EQU 0 (echo OS = Windows 10.0 /Server 2016/Server 2019)
输出结果对,但丑爆,不推荐
利用FOR 循环.
>for /? 查看帮助
@H_750_197@
FOR /F "eol=; tokens=2,3* delims=," %i in (myfile.txt) do @echo %i %j %k would parse each line in myfile.txt, ignoring lines that begin with a semicolon,passing the 2nd and 3rd token from each line to the for body,with tokens delimited by commas and/or spaces. Notice the for body statements reference %i to get the 2nd token, %j to get the 3rd token,and %k to get all remaining tokens after the 3rd. For file names that contain spaces, you need to quote the fil@R_607_8371@s with double quotes. In order to use double quotes in this mAnner, you also need to use the useBACkq option, otherwise the double quotes will be interpreted as defining a literal String to parse. %i is explicitly declared in the for statement and the %j and %k are implicitly declared via the tokens= option. You can specify up to 26 tokens via the tokens= line,provided it does not cause an attempt to declare a variable higher than the letter ‘z‘ or ‘Z‘. Remember,FOR variables are single-letter,case sensitive,global, and you can‘t have more than 52 @R_136_10586@l active at any one time. You can also use the FOR /F parsing logic on an immediate String, by making the file-set between the parenthesis a quoted String, using single quote characters. It will be treated as a single line of input from a file and parsed. Finally,you can use the FOR /F command to parse the output of a command. You do this by making the file-set between the parenthesis a BACk quoted String. It will be treated as a command line,which is passed to a child CMD.EXE and the output is captured into memory and parsed as if it was a file. So the following example: FOR /F "useBACkq delims==" %i IN (`set`) DO @echo %i would enumerate the environment variable names in the current environment.
@echo off for /f "tokens=4-5 delims=. " %%i in (‘ver‘) do set VERSION=%%i.%%j if "%version%" == "6.0" echo Windows Vista/Server 2008 if "%version%" == "6.1" echo Windows 7/Server 2008 R2 if "%version%" == "6.2" echo Windows 8/Server 2012 if "%version%" == "6.3" echo Windows 8.1/Server 2012R2 if "%version%" == "10.0" echo Windows 10.0/Server 2016/Server 2019
[参考]
https://helloacm.com/windows-batch-script-to-detect-windows-version/
以上是大佬教程为你收集整理的用批处理抓取Windows版本信息全部内容,希望文章能够帮你解决用批处理抓取Windows版本信息所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。