通过pnputil安装驱动程序

时间:2016-06-01 11:07:16

标签: windows driver nsis inf

我试图通过NSIS安装.inf文件,如(Installing a driver in NSIS script)。

安装本身运行顺畅,但Windows使用其内部发布的名称(递增的数字oemxxx.inf)安装驱动程序。

如何让pnputil.exe将发布的名称作为返回值(以供日后使用)?

4 个答案:

答案 0 :(得分:2)

我在nsis中获得已发布的drivername所做的是这是一个解决方法:

  1. 通过pnputil /e > driverlist_before.txt
  2. 将已安装的驱动程序列表放入文本文件中
  3. 通过pnputil /i /a mydriver.inf
  4. 安装新驱动程序
  5. 通过pnputil /e > driverlist_after.txt
  6. 将已安装的驱动程序列表放入文本文件中
  7. 将以下代码放在.cmd文件中,并通过nsExec
  8. 执行

    GetPublishedDrivername.cmd

    的内容
    @echo off
    :: look at differences between files and just keep the line with the oem info
    fc mydriverlist_before.txt mydriverlist_after.txt | findstr /C:"oem" > diff.txt
    :: cut result and keep second part               "           oem##.inf"
    for /f "tokens1,2 delims=:" %%a in (diff.txt) do (
      if "%%a"=="Published name " set info=%%b
    )
    :: get rid of leading spaces                     "oem##.inf"
    for /f "tokens=* delims= " %%a in ("%info%") do set info=%%a
    :: split "oem##.inf" and keep first part         "oem##"
    for /f "tokens=1,2 delims=." %%a in ("%info%") do set info=%%a 
    :: get of the oem part                           "##"
    set info=%info:oem=%
    :: convert string into int value
    set /a info=%info%
    del diff.txt
    :: return number as result
    exit /b %info%
    

    这个脚本肯定可以优化,欢迎每一个输入。

答案 1 :(得分:1)

我认为这是不可能的。以下是PnPUtil的所有命令列表:

Microsoft PnP Utility

用法:

pnputil.exe [ - f | -一世] [ -? | -a | -d | -e]

示例:

pnputil.exe -a a:\ usbcam \ USBCAM.INF - >添加USBCAM.INF指定的包

pnputil.exe -a c:\ drivers * .inf - >在c:\ drivers \

中添加所有包

pnputil.exe -i -a a:\ usbcam \ USBCAM.INF - >添加并安装驱动程序包

pnputil.exe -e - >枚举所有第三方套餐

pnputil.exe -d oem0.inf - >删除包oem0.inf

pnputil.exe -f -d oem0.inf - >强制删除包oem0.inf

pnputil.exe - ? - >此用法屏幕

因此,您无法轻松提取该信息并将其传递给NSIS :(

答案 2 :(得分:0)

Pnputil不会这样做,但您可以通过

获取有关oem(数字).inf文件的详细信息
     dism /online /get-driverinfo /driver:oem(number).inf

您将获得以下列表:

部署映像服务和管理工具 版本:10.0.14393.0

图像版本:10.0.14393.0

驱动程序包信息:

已发布名称:oem3.inf 驱动程序存储路径:C:\ Windows \ System32 \ DriverStore \ FileRepository \ us003.inf_amd64_daf71ec003559d2a \ us003.inf 班级名称:打印机 课程描述:打印机 类GUID:{4D36E979-E325-11CE-BFC1-08002BE10318} 日期:2015年9月14日 版本:3.0.3.0 引导严重:否

架构驱动程序:x86

Manufacturer : Samsung
Description : Samsung Universal Print Driver 3
Architecture : x86
Hardware ID : USBPRINT\SamsungML-21500EDE
Service Name : 
Compatible IDs : 
Exclude IDs : 

Manufacturer : Samsung
Description : Samsung Universal Print Driver 3
Architecture : x86
Hardware ID : WSDPRINT\SamsungML-21500EDE
Service Name : 
Compatible IDs : 
Exclude IDs : 

Manufacturer : Samsung
Description : Samsung Universal Print Driver 3
Architecture : x86
Hardware ID : USBPRINT\SamsungSCX-6x45_Seri402B
Service Name : 
Compatible IDs : 
Exclude IDs : 

....与许多其他人一起

答案 3 :(得分:0)

我知道这是一个老问题,但也许这个答案对某人还是有用的... 这就是我用的:

SET OEMNUM=-1
FOR /L %%G IN (1,1,200) DO (
dism /online /get-driverinfo /driver:oem%%G.inf >temp.txt
find "something.inf" temp.txt >nul && SET OEMNUM=%%G
)
pnputil /delete-driver oem%oemnum%.inf /force

基本上,它会检查每个OEM#的详细信息,直到找到所需的INF,然后使用pnputil将其删除。 如果不存在,pnputil将尝试删除不存在的“ oem-1.inf”(从0到无穷大)。

相关问题