【学习笔记】通过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
相关推荐
计算机编程-吉哥39 分钟前
脑肿瘤MRI智能识别系统:基于深度学习的像素级脑肿瘤语义分割平台【计算机毕业设计选题推荐】
人工智能·python·深度学习·算法·毕业设计·课程设计·大数据毕业设计选题推荐
小木_.42 分钟前
Python 离线识别滑块缺口距离,项目推荐
开发语言·python·滑块识别·人机验证·滑块缺口·缺口识别
kakakahahahaha1 小时前
Windows笔记本重装系统的4种路径和风险边界
windows·电脑·笔记本电脑·内容运营·软件需求·重装系统
Cenxi1 小时前
Python字符串方法练习手册
人工智能·python
liliangcsdn1 小时前
因子权重矩阵处理-因子权重收缩Shrinkage算法的探索
开发语言·python·机器学习
用户8356290780511 小时前
使用 Python 在 Excel 中添加和编辑形状
后端·python
2601_962300471 小时前
python在运维上可以干什么,请举几个具体的例子
运维·python·系统管理·网络监控·自动化脚本
小刘在重生~1 小时前
Java 异常体系完整笔记
java·笔记·python
用户8356290780511 小时前
使用 Python 为 PDF 添加和管理超链接
后端·python
千千寰宇2 小时前
[Python/测试] pytest:简洁、可扩展的 Python 测试框架
python·软件质量保障与测试