列出驱动程序相关文件及其版本

List Driver related files and their versions

有什么方法或教程可以吗:

  1. 列出与驱动相关的所有文件
  2. 列出这些文件(.exe、.dll、.sys 等)的文件版本

我正在尝试编译计算机中安装的所有驱动程序的列表,主要列出与驱动程序相关的所有文件(exe、sys、dll 等)以及文件版本。请看附图。

Link to picture:

我尝试使用 Wmi-Object (Powershell) 和 DevCon 工具,但可以列出这些文件。

使用 Powershell,我能够列出驱动程序名称,但只显示文件。

# Script to output all of the drivers installed in the computer

# Export all driver names to a text file
Get-WmiObject win32_SystemDriver | select name | foreach {$_.name} | Out-File C:\driverName.csv

# Read driver name from file.
$driver =  Get-Content "C:\driverName.csv"

# Get the file path of the driver
$path = (Get-WmiObject win32_SystemDriver | Where-Object name -match $driverName).PathName

# Extract information from the file path and export it to CSV
(Get-Item $path).VersionInfo  | Select FileDescription, ProductVersion, FileVersion, FileName | Export-Csv -Path C:\FileVersion.csv
Get-WmiObject -Class Win32_SystemDriver | 
Select-Object Name,PathName,@{N='FileInfo';E={Get-Item -Path $_.pathname | Select-Object -ExpandProperty VersionInfo | Select-Object FileDescription, ProductVersion, FileVersion, FileName}}  | 
    Export-Clixml C:\temp\drivers.xml

$ImportedXML = Import-Clixml -Path C:\temp\drivers.xml

$ImportedXML | Where-Object Name -eq '3ware' | Select-Object -ExpandProperty fileinfo

由于您要查找的信息隐藏在嵌套的 属性 下,因此您不能将结构导出到 'CSV' 之类的平面文件,当然也不能不进行一些自定义。无论如何,更好的选择是将输出存储在 xml 文件中,如上所示,并在需要时检索信息。

使用 DevCon 实用程序列出有关计算机中安装的所有驱动程序的信息。

  1. here 下载 DevCon 包:
  2. 解压包
  3. Admin打开CMD并将目录更改为解压文件夹
  4. 运行 devcon.exe driverfiles *
  5. 它将列出计算机中安装的所有驱动程序、它们的硬件 ID、.inf 文件以及与该特定驱动程序关联的所有其他文件。

这是一个完全符合要求的 Powershell 脚本:

#
$hostname = $ENV:COMPUTERNAME

# Get Third Party drivers used, that are not provided by Microsoft and presumably included in the OS
$drivers = Get-WmiObject Win32_PNPSignedDriver | where {$_.DriverProviderName -ne "Microsoft"}

# Initialize the list of detected driver packages as an array
$DriverFolders = @()
foreach ($d in $drivers) {
    # We initialize the list of driver files for each driver
    $DriverFiles = @()
    # For each driver instance from WMI class Win32_PNPSignedDriver, we compose the related WMI object name from the other WMI driver class, Win32_PNPSignedDriverCIMDataFile
    $ModifiedDeviceID = $d.DeviceID -replace "\", "\"
    $Antecedent = "\" + $hostname + "\ROOT\cimv2:Win32_PNPSignedDriver.DeviceID=""$ModifiedDeviceID"""
    # Get all related driver files for each driver listed in WMI class Win32_PNPSignedDriver
    $DriverFiles += Get-WmiObject Win32_PNPSignedDriverCIMDataFile | where {$_.Antecedent -eq $Antecedent}
    $DriverName = $d.DeviceName
    $DriverID = $d.DeviceID
    Write-Host "####Driver files for driver with name: $DriverName" -ForegroundColor Green
    Write-Host "and with DriverID: $DriverID" -ForegroundColor Green
    foreach ($i in $DriverFiles) {
            # We elliminate double backslashes from the file paths
            $path = $i.Dependent.Split("=")[1] -replace '\\', '\'
            $path2 = $path.Substring(1,$path.Length-2)
            $InfItem = Get-Item -Path $path2
            $Version = $InfItem.VersionInfo.FileVersion
            Write-Output "File: $path2"
            Write-Output "Version: $Version"
    }
    }
#

您可以从此开始做更多的事情,甚至可以从检测到的系统已安装和使用的文件中提取所有与驱动程序相关的文件。

可以找到更复杂的脚本版本 here