Parsing pnputil

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bijiont
Posts: 2
Joined: 11 Dec 2013 21:18

Parsing pnputil

#1 Post by Bijiont » 11 Dec 2013 22:13

Hello Everyone,

I have searched this site for a while and didn't really see my answer so figured I would join and ask in the event it may help someone else in the future.

Currently I am trying to setup a batch file which will take output from pnputil, parse the data and pass on variables to have items deleted based on the parse.

Will be honest I haven't scripted anything in a very long time so I am having a hard time recalling what exactly I did.

I know this isn't complete but here is what I have so far;

Code: Select all

@ECHO OFF

SETLOCAL EnableDelayedExpansion

pnputil.exe -e > C:\test.txt
FOR /F "tokens=2* delims=:" %%G IN (C:\test.txt) DO CALL :SORT

:SORT

DEL C:\test.txt



I think my thought process on this is flawed.

The other part which I am a little confused on is the IF statement to actually perform the parse for what I need. I require the .INF name that has the driver package provider of HP. Can I just set a variable of HP then recursive search 2 line prior?

I am not wanting someone just to "do it for me" but if someone could point me in the right direction I would appreciate it. Would rather do it myself and learn than have it just handed to me not knowing how it works.

Thanks again~

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parsing pnputil

#2 Post by foxidrive » 11 Dec 2013 23:09

If you need some help you have to show the output of the tool that you are trying to capture, and what you need to extract.

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

Re: Parsing pnputil

#3 Post by Aacini » 11 Dec 2013 23:47

I even didn't knew such command! I tested it in my computer (Spanish version) and got this (segment):

Code: Select all

Utilidad PnP de Microsoft

Nombre publicado:            oem5.inf
Proveedor de paquete de controladores:   AMD
Clase:                     Controladoras ATA/ATAPI IDE
Fecha y versión del controlador:   07/23/2012 1.3.001.0043
Nombre del firmante:               Microsoft Windows Hardware Compatibility Publisher

Nombre publicado:            oem22.inf
Proveedor de paquete de controladores:   AMD
Clase:                     Controladoras ATA/ATAPI IDE
Fecha y versión del controlador:   11/30/2012 1.3.001.0068
Nombre del firmante:               Microsoft Windows Hardware Compatibility Publisher

Nombre publicado:            oem18.inf
Proveedor de paquete de controladores:   Hewlett-Packard
Clase:                     Controladoras de bus serie universal
Fecha y versión del controlador:   08/13/2012 7.0.0.25
Nombre del firmante:               Microsoft Windows Hardware Compatibility Publisher

Nombre publicado:            oem1.inf
Proveedor de paquete de controladores:   Intel Corporation
Clase:                     Controladoras ATA/ATAPI IDE
Fecha y versión del controlador:   07/31/2012 11.5.2.1001
Nombre del firmante:               Microsoft Windows Hardware Compatibility Publisher

I then wrote this program to get one line before the ones with "Hewlett-Packard":

Code: Select all

@echo off
setlocal EnableDelayedExpansion

for /F "tokens=2 delims=:" %%a in ('pnputil -e') do for /F "tokens=*" %%b in ("%%a") do (
   if "%%b" equ "Hewlett-Packard" (
      echo !line1prior!
   ) else (
      set "line1prior=%%b"
   )
)


And got this:

Code: Select all

oem18.inf
oem19.inf
oem15.inf
oem16.inf


If the English version have the desired result two lines before, just a small adjust is required...

Antonio

Bijiont
Posts: 2
Joined: 11 Dec 2013 21:18

Re: Parsing pnputil

#4 Post by Bijiont » 12 Dec 2013 00:39

Slightly different output Aacini but I see what you did you parse the actual output.

I can take it from there an place in a delete function that was a huge help.

Will take what you did apart so that I can understand it all for my own learning.

Side note, pnputil is an amazing utility for troubleshooting drivers and such. Delete the OEM.INF file associated with what you are having issues with and reload corrects so many issues.

Post Reply