【发布时间】:2016-06-01 11:07:16
【问题描述】:
我正在尝试通过 NSIS 安装一个 .inf 文件,例如 (Installing a driver in NSIS script)。
安装本身运行顺利,但 Windows 使用其内部发布名称(递增编号 oemxxx.inf)安装驱动程序。
如何让 pnputil.exe 将发布的名称作为返回值给我(供以后使用)?
【问题讨论】:
我正在尝试通过 NSIS 安装一个 .inf 文件,例如 (Installing a driver in NSIS script)。
安装本身运行顺利,但 Windows 使用其内部发布名称(递增编号 oemxxx.inf)安装驱动程序。
如何让 pnputil.exe 将发布的名称作为返回值给我(供以后使用)?
【问题讨论】:
我在 nsis 中获取已发布的驱动程序名称是一种解决方法:
pnputil /e > driverlist_before.txt将已安装驱动程序列表放入文本文件
pnputil /i /a mydriver.inf安装新驱动
pnputil /e > driverlist_after.txt将已安装驱动程序列表放入文本文件
nsExec执行
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%
这个脚本肯定可以优化的,欢迎大家提出意见。
【讨论】:
我认为这是不可能的。以下是 PnPUtil 的所有命令列表:
微软即插即用实用程序
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 -> 枚举所有 3rd 方包
pnputil.exe -d oem0.inf -> 删除包oem0.inf
pnputil.exe -f -d oem0.inf -> 强制删除包oem0.inf
pnputil.exe -? -> 此使用屏幕
因此,您无法轻松提取该信息并将其传递给 NSIS :(
【讨论】:
Pnputil 不会这样做,但您可以通过这样做来获取有关 oem(number).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 :
....可能还有很多人
【讨论】:
我知道这是一个老问题,但也许这个答案对某人仍然有用...... 这是我使用的:
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 到无穷大)。
【讨论】: