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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#1 Post by md73code » 29 Jul 2015 16:53

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)

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

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

#2 Post by Squashman » 29 Jul 2015 17:53

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

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

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

#3 Post by Meerkat » 30 Jul 2015 00:05

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

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

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

#4 Post by Compo » 30 Jul 2015 12:06

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.

imyashy
Posts: 9
Joined: 10 Dec 2023 17:05

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

#5 Post by imyashy » 16 Dec 2023 17:39

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

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#6 Post by Aacini » 17 Dec 2023 11:45

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

imyashy
Posts: 9
Joined: 10 Dec 2023 17:05

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

#7 Post by imyashy » 17 Dec 2023 15:20

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

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

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

#8 Post by Squashman » 17 Dec 2023 19:06

Your code is just echoing to the screen what the pnputil execution would do.

Post Reply