Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a driver via pnputil

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)?

like image 453
machine Avatar asked Jun 01 '16 11:06

machine


People also ask

How do I use PnPUtil EXE?

To run PnPUtil, open a Command Prompt window (Run as Administrator) and type a command using the following syntax and parameters. Note PnPUtil (PnPUtil.exe) is included in every version of Windows, starting with Windows Vista (in the %windir%\system32 directory). PNPUTIL [/add-driver <...> | /delete-driver <...>

Can I update drivers from Command Prompt?

Solution: Updating Drivers Using Command Prompt. *Note – Command Prompt method will not get the driver package from the web. You will have to download the driver package on your own by visiting the OEM website or by simply transferring it to your computer using a pen drive or any other form of external storage media.


2 Answers

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.

like image 190
machine Avatar answered Oct 03 '22 15:10

machine


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 :(

like image 42
Slappy Avatar answered Oct 03 '22 15:10

Slappy