1

I have a deployment that installs a driver and I want to provide the ability to uninstall.

Im leveraging the PNPUTIL.exe tool.

I know the syntax to delete and uninstall the driver, ex:

pnputil.exe /delete-driver oem103.inf /uninstall /force

But my issue, is the oem*.inf number designation is random on each machine, so I can't hard code the .inf into the command and call it a day.

pnputil has /enum-driver switch that will give you details of all the drivers in the DriverStore. Among the line items is the original name of .inf (something I can work with) and the oem# associated with it.

So what I need help with is scripting something that will enumerate the drivers pipe the results to the command to be able the run /delete-drive and /uninstall switches

I tried messing with the Find and FindSTR commands, but it only returned the one line which was the name of the original .inf. I need the OEM# associated with original name of the .inf to be piped to the command.

ItsPete
  • 2,363
  • 3
  • 27
  • 35
Jay Hijazi
  • 13
  • 2

1 Answers1

0

In the output of pnputil, the desired oemXX.inf is one line above the Original Name. So numerate the output, look for the original name and subtract one from the line number. This is the line number where you find the oemXX.inf.

Then find that line and extract the oemXX string. (the for %%b is to get rid of the leading spaces)

@echo off
setlocal 
set "Orig=rt640x64.inf"
pnputil /enum-drivers |findstr /n "^" > pnputil.txt
for /f "delims=:" %%a in ('findstr /c:" %Orig%" pnputil.txt') do set /a line=%%a-1
for /f "tokens=3 delims=:" %%a in ('findstr /b "%line%:" pnputil.txt') do for %%b in (%%a) do set "oem=%%b"
echo "%oem%"

Note: the output of pnputil is language-dependent, but this code doesn't look for words (except the "Original name" of course) but for line numbers, so it should work on all languages.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Dude! Thank you, I had the right idea, but was no where near this. Really appreciate it! This did the trick! – Jay Hijazi Sep 30 '19 at 14:25