用批处理抓取Windows版本信息
发布时间:2020-12-13 22:31:34 所属栏目:Windows 来源:网络整理
导读:[1]Python 环境下比较简单,调用platform 模块即可 [2]没有Python 情况下,可以用ver 命令实现。 ? verMicrosoft Windows [Version 10.0.16299.967] ? a自动化用简单的Batch脚本[不推荐] :: ------------------------------------- :: Check Windows Version
[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) 输出结果对,但丑爆,不推荐 ? <b>更少代码和更精确的输出 利用FOR 循环. >for /? 查看帮助 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 filenames 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 total 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-7 – 在Windows 7中使用Open MPI和CUDA
- windows – WriteProcessMemory ERROR_PARTIAL_COPY 299
- 使用Windows 7- 64位更新Android SDK Tools rev 19 to rev
- 缓存 – 寻求Akavache文档或示例
- 同步域内时间方法一:net time
- windows – 关于汇编程序远程调用和天堂之门,在抛出异常之前
- windows驱动WorkItem
- Windows:如何启动docker VM att系统启动
- 是否可以在Windows中执行Objective-C程序?
- 如何允许从Windows资源管理器拖放到C#WPF应用程序?
推荐文章
站长推荐
- windows-server-2012 – 对共享文件夹的NetworkS
- windows-server-2008-r2 – 没有源IP的事件ID 46
- windows – 有没有办法改变MATLAB命令窗口的标题
- windows – App-V有什么好处?
- winapi – 防止Windows的打开文件对话框检查读取
- windows-server-2008-r2 – Windows server 2008
- Microsoft Git Provider和Visual Studio 2012无法
- windows-server-2008 – 我可以在没有安装远程桌
- 在各种Windows版本上有什么样的SCTP支持?
- windows – 从命令行创建一个无声的mp3
热点阅读