【学习笔记】通过windows自带命令WMIC,查询浏览器版本号信息,对比Selenium驱动的版本号信息

【简单介绍】

WMIC 是 Windows Management Instrumentation Command-line 的缩写,是一个功能强大的 Windows 命令行工具,可以用于访问和管理 Windows Management Instrumentation (WMI) 提供的各种信息和功能。

WMIC datafile 是 WMIC 的一个子命令,用于管理和查询文件系统中的文件信息。以下是 WMIC datafile 的主要管理命令:

【管理命令】

  1. **get**: 用于获取文件的属性信息,如文件名、路径、版本、大小、创建时间和修改时间等。

示例:

```

C:\> wmic datafile where "name='notepad.exe'" get Name,Path,Version,Size,CreationDate,LastModified

```

  1. **list**: 列出符合条件的文件信息。

示例:

```

C:\> wmic datafile list brief

```

  1. **where**: 用于过滤查询结果,支持多个条件。

示例:

```

C:\> wmic datafile where "name='notepad.exe'" get Name,Path,Version

```

  1. **assoc**: 用于关联文件扩展名与文件类型。

示例:

```

C:\> wmic datafile where Extension=".txt" assoc

```

  1. **call**: 用于执行 WMI 方法。

示例:

```

C:\> wmic datafile where Name="notepad.exe" call Rename NewName="notepad2.exe"

```

【扩展命令】

下面是 WMIC datafile 扩展指令的详细介绍:

  1. **Name**: 文件名,包括扩展名。例如: "notepad.exe"。

  2. **Path**: 文件的完整路径。例如: "C:\Windows\System32\notepad.exe"。

  3. **Version**: 文件的版本信息。例如: "6.1.7601.17514"。

  4. **Size**: 文件的大小,以字节为单位。例如: "69632"。

  5. **CreationDate**: 文件的创建日期和时间。例如: "20090713225622.000000+000"。

  6. **LastModified**: 文件的最后修改日期和时间。例如: "20090713225622.000000+000"。

  7. **Drive**: 文件所在的驱动器器盘符。例如: "C"。

  8. **Directory**: 文件所在的目录路径。例如: "\Windows\System32"。

  9. **FileName**: 文件名,不包括扩展名。例如: "notepad"。

  10. **Extension**: 文件扩展名。例如: ".exe"。

下面是一个示例,演示如何使用 WMIC datafile 命令查询 notepad.exe 文件的所有信息:

```

【官方举例】

C:\> wmic datafile where "name='notepad.exe'" get Name,Path,Version,Size,CreationDate,LastModified,Drive,Directory,FileName,Extension

Name Path Version Size CreationDate LastModified Drive Directory FileName Extension

notepad.exe C:\Windows\System32\notepad.exe 6.1.7601.1 69632 20090713225622.000000+000 20090713225622.000000+000 C \Windows\System32 notepad .exe

```

从上面的输出可以看到,notepad.exe 文件位于 C:\Windows\System32 目录下,版本号为 6.1.7601.1,文件大小为 69,632 字节,创建时间为 2009-07-13 22:56:22,最后修改时间也是 2009-07-13 22:56:22。

【举例】

wmic datafile /?

动词有ASSOC,CALL,CREATE,DELETE,GET,LIST 这几个

命令:

wmic datafile where "filename='dsc04059' and extension='jpg' and drive='f:'" list /format:value

结果:

AccessMask=18809343

Archive=TRUE

Caption=f:\dsc04059.jpg

Compressed=FALSE

CompressionMethod=

CreationClassName=CIM_LogicalFile

CreationDate=20091012174149.578125+480

CSCreationClassName=Win32_ComputerSystem

CSName=20090621-1240

Description=f:\dsc04059.jpg

Drive=f:

EightDotThreeFileName=f:\dsc04059.jpg

Encrypted=FALSE

EncryptionMethod=

Extension=jpg

FileName=dsc04059

FileSize=86092

FileType=Kankan JPEG 图像

FSCreationClassName=Win32_FileSystem

FSName=NTFS

Hidden=FALSE

InstallDate=20091012174149.578125+480

InUseCount=

LastAccessed=20100412155336.781250+480

LastModified=20091009140702.000000+480

Manufacturer=

Name=f:\dsc04059.jpg

Path=\

Readable=TRUE

Status=OK

System=FALSE

Version=

Writeable=TRUE

实例:

DATAFILE -- DataFile 管理

::查找e盘下test目录(不包括子目录)下的cc.cmd文件

wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" list

::查找e盘下所有目录和子目录下的cc.cmd文件,且文件大小大于1K

wmic datafile where "drive='e:' and FileName='cc' and Extension='cmd' and FileSize>'1000′" list

::删除e盘下文件大小大于10M的.cmd文件

wmic datafile where "drive='e:' and Extension='cmd' and FileSize>'10000000′" call delete

::删除e盘下test目录(不包括子目录)下的非.cmd文件

wmic datafile where "drive='e:' and Extension<>'cmd' and path='test'" call delete

::复制e盘下test目录(不包括子目录)下的cc.cmd文件到e:\,并改名为aa.bat

wmic datafile where "drive='e:' and path='\\test\\' and FileName='cc' and Extension='cmd'" call copy "e:\aa.bat"

::改名c:\hello.txt为c:\test.txt

wmic datafile "c:\\hello.txt" call rename c:\test.txt

::查找h盘下目录含有test,文件名含有perl,后缀为txt的文件

wmic datafile where "drive='h:' and extension='txt' and path like '%\\test\\%' and filename like '%perl%'" get name

【常用命令】

获取版本号信息:

wmic datafile where name="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" get version / value
wmic datafile where name="C:\\Program Files\\Microsoft\Edge\\Application\\msedge.exe" get version / value
wmic datafile where name="D:\\Program Files\\FireFox\\firefox.exe" get Manufacturer,Version,Filename / value

python 复制代码
#!/usr/bin/env/python3
# -*- coding:utf-8 -*-
import os
import subprocess

# wmic datafile where name="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" get version / value
# wmic datafile where name="C:\Program Files\Google\Chrome\Application\chrome.exe" get version / value
# wmic datafile where name="D:\\Program Files\\FireFox\\firefox.exe" get version / value

code = r"""
wmic datafile where name="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" get version / value
wmic datafile where name="D:\Test Files\Python385\msedgedriver.exe" get version / value
"""

codelist = code.split("\n")
for cmd in codelist[0:]:
    ''' ①os.system(),没有返回值,改为用os.open();
        ②通过文件路径,获取文件版本号信息,赋值为list'''
    if cmd:
        cmd = cmd.replace("\\","\\\\")
        cmd_get_version = cmd
        result_list_str = "".join([c for c in os.popen(cmd_get_version).readlines() if len(c) > 10])
        print(cmd)
        print(result_list_str)  # Version=121.0.6167.85
相关推荐
渣渣苏4 分钟前
Langchain实战快速入门
人工智能·python·langchain
lili-felicity13 分钟前
CANN模型量化详解:从FP32到INT8的精度与性能平衡
人工智能·python
数据知道16 分钟前
PostgreSQL实战:详解如何用Python优雅地从PG中存取处理JSON
python·postgresql·json
呉師傅22 分钟前
【使用技巧】Adobe Photoshop 2024调整缩放与布局125%后出现点菜单项漂移问题的简单处理
运维·服务器·windows·adobe·电脑·photoshop
ZH154558913129 分钟前
Flutter for OpenHarmony Python学习助手实战:面向对象编程实战的实现
python·学习·flutter
玄同76529 分钟前
SQLite + LLM:大模型应用落地的轻量级数据存储方案
jvm·数据库·人工智能·python·语言模型·sqlite·知识图谱
User_芊芊君子34 分钟前
CANN010:PyASC Python编程接口—简化AI算子开发的Python框架
开发语言·人工智能·python
白日做梦Q1 小时前
Anchor-free检测器全解析:CenterNet vs FCOS
python·深度学习·神经网络·目标检测·机器学习
喵手1 小时前
Python爬虫实战:公共自行车站点智能采集系统 - 从零构建生产级爬虫的完整实战(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·采集公共自行车站点·公共自行车站点智能采集系统·采集公共自行车站点导出csv
喵手1 小时前
Python爬虫实战:地图 POI + 行政区反查实战 - 商圈热力数据准备完整方案(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·地区poi·行政区反查·商圈热力数据采集