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

时间:2015-06-22 23:20:35

标签: windows powershell drivers devcon

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

  1. 列出与驱动程序相关的所有文件
  2. 列出这些文件的文件版本(.exe,.dll,.sys等)
  3. 我正在尝试编译计算机中安装的所有驱动程序的列表,主要列出与驱动程序(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
    

3 个答案:

答案 0 :(得分:2)

这是一个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

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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文件中,如上所示,并在需要时检索信息。