【学习笔记】通过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
   ```

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

   示例:
   ```
   C:\> wmic datafile list brief
   ```

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

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

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

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

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

#!/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


 

  • 23
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值