【学习笔记】通过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
相关推荐
麦麦大数据12 分钟前
F024 CNN+vue+flask电影推荐系统vue+python+mysql+CNN实现
vue.js·python·cnn·flask·推荐算法
Zzz 小生18 分钟前
编程基础学习(一)-Python基础语法+数据结构+面向对象全解析
开发语言·python
white-persist18 分钟前
JWT 漏洞全解析:从原理到实战
前端·网络·python·安全·web安全·网络安全·系统安全
久未1 小时前
Pytorch autoload机制自动加载树外扩展(Autoload Device Extension)
人工智能·pytorch·python
wulitoud1 小时前
[好用工具] 一款mac/windows电脑历史剪切板工具,类似著名的Paste
windows·macos·sublime text
java1234_小锋1 小时前
TensorFlow2 Python深度学习 - TensorFlow2框架入门 - 使用Keras.Model来定义模型
python·深度学习·tensorflow·tensorflow2
Learn Beyond Limits1 小时前
TensorFlow Implementation of Content-Based Filtering|基于内容过滤的TensorFlow实现
人工智能·python·深度学习·机器学习·ai·tensorflow·吴恩达
java1234_小锋1 小时前
TensorFlow2 Python深度学习 - 函数式API(Functional API)
python·深度学习·tensorflow·tensorflow2
Y200309161 小时前
使用 PyTorch 实现 MNIST 手写数字识别
python
马尚来1 小时前
移动端自动化测试Appium,从入门到项目实战Python版
python