Page 1 of 1

Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 29 Jul 2015 16:53
by md73code
Hi guys s there a convenient way to create a batch file to delete these .inf (in my case graphic driver) files from my manual procedure listed below?

-Open ADMIN CMD prompt.
-Type: pnputil.exe -e (This shows all the .inf files from drivers installed)
-Type: pnputil.exe -d oem###.inf (The specific .inf file)

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 29 Jul 2015 17:53
by Squashman
On my phone and I do not know what the output of the pnputil program looks like.

Code: Select all

for /f "delims=" %%G in ('pnputil -e') do pnputil -d %%G

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 30 Jul 2015 00:05
by Meerkat

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /f "tokens=1,* delims=:" %%i in (
   'pnputil -e^|findstr /b /c:"Published name :"'
) do (
   set "X=%%j"
   pnputil.exe -d "!X: =!"
)
pause


This is untested because I am scared :|

Meerkat

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 30 Jul 2015 12:06
by Compo
WARNING, The responses so far would delete all drivers!

Since the OP stated graphics drivers, here is an English language based solution using the tool stated.

Code: Select all

@Echo Off
SetLocal
For /F "Tokens=1,3,4" %%A In ('PnPUtil -e') Do (
   If "%%A" Equ "Published" Set "_=%%C"
   If "%%B %%C" Equ "Display adapters" Call Echo=PnPUtil -d -f %%_%%)
Pause

If you're happy with the solution, remove the five characters Echo= on line five and all of line six.

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 16 Dec 2023 17:39
by imyashy
Hi,

How can this script be adapted so that it deletes the driver oem##.inf package for the driver that contains 12/13/2016 1.0.0.2.

Manually this would be done like so:

-Open ADMIN CMD prompt.
-Type: pnputil.exe -e (This shows all the .inf files from drivers installed)
- Search through the list to identify the oem##.inf for the driver which has a driver date and version of 12/13/2016 1.0.0.2
-Type: pnputil.exe -f -d oem##.inf

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 17 Dec 2023 11:45
by Aacini
In the code of this answer:
  • Change @echo %%b by set "driver=%%b"
  • Insert pnputil.exe -f -d %driver% at end
Ops! This don't works because the pipe!

Modify the core code in this way:

Code: Select all

pnputil -e > test.txt
findstr /R /C:".*!\n!.*!\n!.*!\n!.*%search%" test.txt > test2.txt
for /F "tokens=2 delims=:" %%a in (test2.txt) do for /F "tokens=*" %%b in ("%%a") do set "driver=%%b"
pnputil.exe -f -d %driver%
del test.txt test2.txt
Antonio

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 17 Dec 2023 15:20
by imyashy
Thank you Aacini. That works. Driver is found and then deleted.

I wanted to keep this code in my toolbox too from Compo, and apply it to smart card readers but it doesn't work any I don't know why. I expected it to delete all smart card reader drivers on the machine but it doesn't. Not sure where it is failing.

Code: Select all

@Echo Off
SetLocal
For /F "Tokens=1,3,4" %%A In ('PnPUtil -e') Do (
   If "%%A" Equ "Published" Set "_=%%C"
   If "%%B %%C" Equ "Smart card readers" Call Echo=PnPUtil -d -f %%_%%)
Pause

Re: Batch file to delete .inf files from a ADMIN CMDprompt.

Posted: 17 Dec 2023 19:06
by Squashman
Your code is just echoing to the screen what the pnputil execution would do.