从ManagementObjectSearcher获取inf的位置

时间:2012-06-25 19:20:06

标签: c# wmi

我正在使用以下代码遍历Windows中的所有设备驱动程序。我能够找到INF名称,但是,我无法找到INF位置。任何帮助都很棒。

ManagementObjectSearcher searcher = 
            new ManagementObjectSearcher("SELECT * FROM Win32_PnPSignedDriver");
foreach (ManagementObject obj in searcher.Get())
{
    if(obj["DriverProviderName"] != null)
    {
        foreach (PropertyData prop in obj.Properties)
        {
            Console.WriteLine("{0}: {1}", prop.Name, prop.Value);
        }
    }
}

输出:InfName:hal.inf

hal.inf的位置在哪里?我正在尝试创建一个备份所有设备驱动程序的应用程序。

Hal.inf只是一个例子。

物业外汇示例:

Caption    
ClassGuid   {4D36E968-E325-11CE-BFC1-08002BE10318}
CompatID    PCI\VEN_10DE&DEV_0422&REV_A1
CreationClassName   
Description NVIDIA GeForce 8400 GS 
DeviceClass DISPLAY
DeviceID    PCI\VEN_10DE&DEV_0422&SUBSYS_C7323842&REV_A1\4&31ADF711&0&0008
DeviceName  NVIDIA GeForce 8400 GS 
DevLoader   
DriverDate  20120515000000.******+***
DriverName  
DriverProviderName  NVIDIA
DriverVersion   6.14.13.142
FriendlyName    
HardWareID  PCI\VEN_10DE&DEV_0422&SUBSYS_C7323842&REV_A1
InfName oem25.inf
InstallDate 
IsSigned    True
Location    PCI bus 1, device 0, function 0
Manufacturer    NVIDIA
Name    
PDO \Device\NTPNP_PCI0021
Signer  Microsoft Windows Hardware Compatibility Publisher
Started 
StartMode   
Status  
SystemCreationClassName 
SystemName

2 个答案:

答案 0 :(得分:0)

要检索有关驱动程序文件本身的信息,请查询Win32_SystemDriver表。驱动程序路径由PathName属性提供。

答案 1 :(得分:0)

如果内存对我有用,那么在安装驱动程序时使用的* .inf会被转换为windows的驱动程序存储区,一个oem [0-9] {1,3} .inf文件,您可以在输出中看到。我刚刚使用devcon程序找到我的视频卡hwid然后再次使用devcon来列出驱动程序文件。

在输出中,您将注意到System32 / DriverStore的路径引用。这实际上包含安装期间使用的原始* .inf文件。 :)它的1:1只是将nv_disp.inf与我的oem#.inf区分开来。 Devcon确实为您提供了完整的驱动程序文件列表,这与我与wmi和其他人的经历不同。

这是我正在谈论的参考     C:\ Windows \ System32下\ DriverStore \ FileRepository文件\ nv_disp.inf_amd64_neutral_671aa18aef114cc2 \

所以非常简单!抓住你的HWID | devcon driverfiles |清理结果,添加一点点逻辑| tar old-driver.tar filelist.txt

使用这些备份恢复或做一些有用的事情会有很大不同。每次更新驱动程序时,它都会添加一个新的driverstore文件夹,找出哪一个是最新的并不困难。所以从理论上讲,通过获取一些文件夹统计信息并备份正确的文件,你真的不需要任何东西。您也可以使用PnPutil进行循环并尝试删除所有oem * .inf驱动程序包,它无法删除活动包,因此风险很小,但它可能会稍微清理一下驱动程序。

您在github上提供的Geforce Driver Check脚本中可能也很有用。

你需要下载他们的500meg驱动程序开发工具包ISO并解压缩+重命名两个devcon二进制文件(devconx64.exe和devcon.exe我认为)Devcon可以执行“设备管理器GUI”可以从CMD行执行的所有操作。

$ devcon driverfiles PCI\\VEN_10DE\&DEV_1184
PCI\VEN_10DE&DEV_1184&SUBSYS_37743842&REV_A1\4&2F1C4782&0&0018
    Name: NVIDIA GeForce GTX 770
    Driver installed from C:\Windows\INF\oem8.inf [Section090]. 53 file(s) used by driver:
        C:\Program Files\NVIDIA Corporation\Drs\dbInstaller.exe
        C:\Program Files\NVIDIA Corporation\Drs\nvdrsdb.bin
        C:\Windows\System32\DriverStore\FileRepository\nv_disp.inf_amd64_neutral_671aa18aef114cc2\NvCplSetupEng.exe
        C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\Nvd3d9wrap.dll
        C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\detoured.dll
        C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\nvdxgiwrap.dll
        C:\Program Files\NVIDIA Corporation\coprocmanager\Nvd3d9wrapx.dll
        C:\Program Files\NVIDIA Corporation\coprocmanager\detoured.dll
        C:\Program Files\NVIDIA Corporation\coprocmanager\nvdxgiwrapx.dll
        C:\Program Files\NVIDIA Corporation\license.txt
        C:\Program Files\NVIDIA Corporation\NVSMI\MCU.exe
        C:\Program Files\NVIDIA Corporation\NVSMI\nvdebugdump.exe
        C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.1.pdf
        C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe
        C:\Program Files\NVIDIA Corporation\NVSMI\nvml.dll
        C:\Program Files\NVIDIA Corporation\OpenCL\OpenCL.dll
        C:\Program Files\NVIDIA Corporation\OpenCL\OpenCL64.dll
        C:\Windows\system32\DRIVERS\nvlddmkm.sys
        C:\Windows\system32\NvFBC64.dll
        C:\Windows\system32\NvIFR64.dll
        C:\Windows\system32\NvIFROpenGL.dll
        C:\Windows\system32\nvEncodeAPI64.dll
        C:\Windows\system32\nvapi64.dll
        C:\Windows\system32\nvcompiler.dll
        C:\Windows\system32\nvcuda.dll
        C:\Windows\system32\nvcuvenc.dll
        C:\Windows\system32\nvcuvid.dll
        C:\Windows\system32\nvd3dumx.dll
        C:\Windows\system32\nvinfo.pb
        C:\Windows\system32\nvinitx.dll
        C:\Windows\system32\nvoglshim64.dll
        C:\Windows\system32\nvoglv64.dll
        C:\Windows\system32\nvopencl.dll
        C:\Windows\system32\nvumdshimx.dll
        C:\Windows\system32\nvwgf2umx.dll
        C:\Windows\SysWow64\NvFBC.dll
        C:\Windows\SysWow64\NvIFR.dll
        C:\Windows\SysWow64\NvIFROpenGL.dll
        C:\Windows\SysWow64\nvEncodeAPI.dll
        C:\Windows\SysWow64\nvapi.dll
        C:\Windows\SysWow64\nvcompiler.dll
        C:\Windows\SysWow64\nvcuda.dll
        C:\Windows\SysWow64\nvcuvenc.dll
        C:\Windows\SysWow64\nvcuvid.dll
        C:\Windows\SysWow64\nvd3dum.dll
        C:\Windows\SysWow64\nvinit.dll
        C:\Windows\SysWow64\nvoglshim32.dll
        C:\Windows\SysWow64\nvoglv32.dll
        C:\Windows\SysWow64\nvopencl.dll
        C:\Windows\SysWow64\nvumdshim.dll
        C:\Windows\SysWow64\nvwgf2um.dll
        C:\Windows\system32\nvdispco6433193.dll
        C:\Windows\system32\nvdispgenco6433193.dll
1 matching device(s) found.

Device Console Help:
devcon.exe [-r] [-m:\\<machine>] <command> [<arg>...]
-r           Reboots the system only when a restart or reboot is required.
<machine>    Specifies a remote computer.
<command>    Specifies a Devcon command (see command list below).
<arg>...     One or more arguments that modify a command.
For help with a specific command, type: devcon.exe help <command>
classfilter          Add, delete, and reorder class filters.
classes              List all device setup classes.
disable              Disable devices.
driverfiles          List installed driver files for devices.
drivernodes          List driver nodes of devices.
enable               Enable devices.
find                 Find devices.
findall              Find devices, including those that are not currently attached.
help                 Display Devcon help.
hwids                List hardware IDs of devices.
install              Install a device manually.
listclass            List all devices in a setup class.
reboot               Reboot the local computer.
remove               Remove devices.
rescan               Scan for new hardware.
resources            List hardware resources for devices.
restart              Restart devices.
sethwid              Modify Hardware ID's of listed root-enumerated devices.
stack                List expected driver stack for devices.
status               List running status of devices.
update               Update a device manually.
updateni             Manually update a device (non interactive).
dp_add               Adds (installs) a third-party (OEM) driver package.
dp_delete            Deletes a third-party (OEM) driver package.
dp_enum              Lists the third-party (OEM) driver packages installed on this machine.