Installing a driver via pnputil
Asked Answered
S

4

6

I'm trying to install an .inf file via NSIS like (Installing a driver in NSIS script).

Installation itself works smooth, but Windows installs the driver with its internal published name (an incrementing number oemxxx.inf).

How can I get pnputil.exe to give me the published name as return value (for later usage)?

Stereotypy answered 1/6, 2016 at 11:7 Comment(0)
S
3

What I did to get the published drivername in nsis is this hell of a workaround:

  1. put the list of installed drivers to a text-file via pnputil /e > driverlist_before.txt
  2. install new driver via pnputil /i /a mydriver.inf
  3. put the list of installed drivers to a text-file via pnputil /e > driverlist_after.txt
  4. put following code in a .cmd file and execute it via nsExec

content of 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%

This script can surely be optimized, every input is welcome.

Stereotypy answered 6/6, 2016 at 8:36 Comment(0)
M
1

I think that is not possible. Here is a list of all commands of PnPUtil:

Microsoft PnP Utility

Usage:

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

Examples:

pnputil.exe -a a:\usbcam\USBCAM.INF -> Add package specified by USBCAM.INF

pnputil.exe -a c:\drivers*.inf -> Add all packages in c:\drivers\

pnputil.exe -i -a a:\usbcam\USBCAM.INF -> Add and install driver package

pnputil.exe -e -> Enumerate all 3rd party packages

pnputil.exe -d oem0.inf -> Delete package oem0.inf

pnputil.exe -f -d oem0.inf -> Force delete package oem0.inf

pnputil.exe -? -> This usage screen

So you cannot extract that information and pass it to NSIS easily :(

Mccafferty answered 2/6, 2016 at 5:11 Comment(0)
O
1

Pnputil won't do it, but you can get details about the oem(number).inf file by doing

     dism /online /get-driverinfo /driver:oem(number).inf

You will get back a listing like:

Deployment Image Servicing and Management tool Version: 10.0.14393.0

Image Version: 10.0.14393.0

Driver package information:

Published Name : oem3.inf Driver Store Path : C:\Windows\System32\DriverStore\FileRepository\us003.inf_amd64_daf71ec003559d2a\us003.inf Class Name : Printer Class Description : Printers Class GUID : {4D36E979-E325-11CE-BFC1-08002BE10318} Date : 9/14/2015 Version : 3.0.3.0 Boot Critical : No

Drivers for architecture : 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 : 

.... with maybe many others

Outmost answered 12/4, 2017 at 19:33 Comment(4)
This output is similarly useless as the one from PNPUtil, so I'm not sure how your answer helps with the posted question?Swarm
It helps you match the "useless" numerical name generated by PNPUtil /e in Slappy's comment to actual information about the hardware.Outmost
but how does that help with the NSIS script (the initial question)?Swarm
Point made, that should have been separated into COMMENTS rather than posted as an ANSWER. Thanks.Outmost
C
0

I know this is an old question but maybe this answer is still useful for someone... This is what I use:

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

Basically it checks the details of every OEM# until it finds the INF you are looking for and then, using pnputil, deletes it. If it isn't there, pnputil will attempt to delete "oem-1.inf", which does not exists (it goes from 0 to infinity).

Cnemis answered 9/5, 2019 at 19:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.