用批处理抓取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)

输出结果对,但丑爆,不推荐

<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.

for /f "tokens=4-5 delims=. " %%i in (‘ver‘) do set VERSION=%%i.%%j

@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/

原文地址:https://www.cnblogs.com/ASAP/p/10593130.html

时间: 2024-11-08 14:47:11

用批处理抓取Windows版本信息的相关文章

从网页上抓取Windows补丁信息然后整型输出(Python)

Powershell实现:http://www.cnblogs.com/IvanChen/p/4488246.html 今天通过Python实现: # coding=utf-8 import re import requests import csv import sys from lxml import etree reload(sys) sys.setdefaultencoding('utf8') summaryurl = 'https://technet.microsoft.com/en-

Python爬虫实战---抓取图书馆借阅信息

原创作品,引用请表明出处:Python爬虫实战---抓取图书馆借阅信息 前段时间在图书馆借了很多书,借得多了就容易忘记每本书的应还日期,老是担心自己会违约,影响日后借书,而自己又懒得总是登录到学校图书馆借阅系统查看,于是就打算写一个爬虫来抓取自己的借阅信息,把每本书的应还日期给爬下来,并写入txt文件,这样每次忘了就可以打开该txt文件查看,每次借阅信息改变了,只要再重新运行一遍该程序,原txt文件就会被新文件覆盖,里面的内容得到更新. 用到的技术: Python版本是 2.7 ,同时用到了ur

python实现爬虫(一)--- Scrapy框架抓取豆瓣书籍信息

Scrapy是一个用python实现都爬虫框架,简单易用,功能强大,只需要在框架的基础上自定义自己的分析规则即可,具体如何新建工程等待都在官方文档上面讲解得非常清楚,官方文档tutorial(http://doc.scrapy.org/en/latest/intro/tutorial.html)请保证下载较新版本的Scrapy(我的是0.24.2,scrapy -v)旧版本会出现一些问题. 下面我使用Scrapy抓取豆瓣上面编程书籍的一些简单信息 一.准备爬取的页面如下,新建一个douban工程

scrapy抓取拉勾网职位信息(一)——scrapy初识及lagou爬虫项目建立

本次以scrapy抓取拉勾网职位信息作为scrapy学习的一个实战演练 python版本:3.7.1 框架:scrapy(pip直接安装可能会报错,如果是vc++环境不满足,建议直接安装一个visual studio一劳永逸,如果报错缺少前置依赖,就先安装依赖) 本篇主要对scrapy生成爬虫项目做一个基本的介绍 tips:在任意目录打开cmd的方式可以使用下面这两种方式 shift + 右键打开cmd(window10的powershell你可以简单理解为cmd升级版) 在路径框直接输入cmd

c#实现从其他网站抓取imei码信息,手工输入验证码

阅读全文:http://www.yzswyl.cn/blread-1603.html 功能:从其他网站手工输入验证码并抓取手机IMEI信息 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.For

获取windows版本信息

procedure TForm1.Button1Click(Sender: TObject); Var OSVI:OSVERSIONINFO; begin OSVI.dwOSversioninfoSize:=Sizeof(OSVERSIONINFO); GetVersionEx(OSVI); Caption:=IntToStr(OSVI.dwMinorVersion)+',' +IntToStr(OSVI.dwMinorVersion)+',' +IntToStr(OSVI.dwBuildNum

Java广度优先爬虫示例(抓取复旦新闻信息)

一.使用的技术 这个爬虫是近半个月前学习爬虫技术的一个小例子,比较简单,怕时间久了会忘,这里简单总结一下.主要用到的外部Jar包有HttpClient4.3.4,HtmlParser2.1,使用的开发工具(IDE)为intelij 13.1,Jar包管理工具为Maven,不习惯用intelij的同学,也可以使用eclipse新建一个项目. 二.爬虫基本知识 1.什么是网络爬虫?(爬虫的基本原理) 网络爬虫,拆开来讲,网络即指互联网,互联网就像一个蜘蛛网一样,爬虫就像是蜘蛛一样可以到处爬来爬去,把

教您使用java爬虫gecco抓取JD全部商品信息

gecco爬虫 如果对gecco还没有了解可以参看一下gecco的github首页.gecco爬虫十分的简单易用,JD全部商品信息的抓取9个类就能搞定. JD网站的分析 要抓取JD网站的全部商品信息,我们要先分析一下网站,京东网站可以大体分为三级,首页上通过分类跳转到商品列表页,商品列表页对每个商品有详情页.那么我们通过找到所有分类就能逐个分类抓取商品信息. 入口地址 http://www.jd.com/allSort.aspx,这个地址是JD全部商品的分类列表,我们以该页面作为开始页面,抓取J

Python爬虫技术干货,教你如何实现抓取京东店铺信息及下载图片

什么是Python爬虫开发 Python爬虫开发,从网站某一个页面(通常是首页)开始,读取网页的内容,找到在网页中的其它链接地址,然后通过这些链接地址寻找下一个网页,这样一直循环下去,直到把这个网站所有的网页都抓取完为止.世界上80%的爬虫是基于Python开发的,学好爬虫技能,可为后续的大数据分析.挖掘.机器学习等提供重要的数据源. Python爬虫实例参考 这是一个用Python爬虫实现抓取京东店铺信息以及下载图片的例子,仅供参考. 信息抓取: 图片下载的:注意: 1.在选择信息的时候用CS