Page 1 of 1

Help designing a batch file to return driver information

Posted: 10 Dec 2023 17:34
by imyashy
Hi all,

I'm looking to create a batch file that returns driver information about all connected devices in a specific device class. In this case smartcard readers.

It should look through the results of 'pnputil /enum-devices /drivers /class "smartcardreader"' to find the 'Matching Drivers' attribute and return the following information for each occurance of it. The information appears after the attribute as follows:

- Driver Name
- Original Name
- Provider Name
- Driver Version
- Matching Device ID

I would also like the 'device description' to appear first however this attribute appears before 'Matching Drivers'.

I've included an example below of results from the pnputil command. The information should also be outputted to a text file. Any help would be greatly appreciated.


Instance ID: USB\VID_076B&PID_3031\7&3adb5428&0&1
Device Description: OMNIKEY 3x21
Class Name: SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name: HID Global
Status: Started
Driver Name: oem39.inf
Matching Drivers:
Driver Name: oem39.inf
Original Name: omnikey3x21.inf
Provider Name: HID Global

Class Name SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Driver Version: 12/13/2016 1.0.0.2
Matching Device ID: USB\VID_076B&PID_3031

Driver Rank: 00FF0001
Driver Status: Best Ranked / Installed

Driver Name: wudfusbcciddriver.inf
Provider Name: Microsoft
Class Name SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Driver Version: 06/21/2006 10.0.19041.1
Matching Device ID: USB\Class_0B&SubClass_00&Prot_00
Driver Rank: 00FF2000
Driver Status: Outranked

Re: Help designing a batch file to return driver information

Posted: 12 Dec 2023 20:26
by Compo
A start would be to pipe the output through findstr.exe.

Code: Select all

%SystemRoot%\System32\pnputil.exe /enum-devices /drivers /class SmartCardReader 2>NUL | %SystemRoot%\System32\findstr.exe /RIC:"^De" /C:"^  *Driver [NV]" /C:"^  *[OMP]" /C:"^$"
Obviously this would include the Outranked drivers too, (I've kept the empty line separating them), but would certainly shorten the lines left to parse. (You should note that this method is language dependent)

Re: Help designing a batch file to return driver information

Posted: 15 Dec 2023 16:40
by imyashy
Compo wrote:
12 Dec 2023 20:26
A start would be to pipe the output through findstr.exe.

Code: Select all

%SystemRoot%\System32\pnputil.exe /enum-devices /drivers /class SmartCardReader 2>NUL | %SystemRoot%\System32\findstr.exe /RIC:"^De" /C:"^  *Driver [NV]" /C:"^  *[OMP]" /C:"^$"
Obviously this would include the Outranked drivers too, (I've kept the empty line separating them), but would certainly shorten the lines left to parse. (You should note that this method is language dependent)
Many thanks Compo. The fact that it's one line of code is amazing. I tested the script and it worked. There are some changes I require to the information that is presented though if possible.

I'd like the 'Status' to appear below the Device Description. Also, when the results are returned, some devices have multiple drivers listed as compatible (best and unranked). The driver status values are either

1. Best Ranked / Installed
2. Unranked / Installed
3. Best Ranked
3. Unranked

Is it possible to only return the driver results where the 'driver status' value contains the word Installed? So in the example of the OP, the information for the second driver (wudfusbcciddriver.inf) which has a driver status value of unranked, would not appear. There are some instances where the best ranked driver has been overwritten manually by an unranked driver. In this scenario the driver status attribute reads 'Unranked / Installed'. However, it's worth mentioning that the first driver that always in the list when running the PNPUTIL command is the best ranked one and unranked ones appear below it.

Re: Help designing a batch file to return driver information

Posted: 17 Dec 2023 15:28
by Compo
imyashy wrote:
10 Dec 2023 17:34
<snip /> to find the 'Matching Drivers' attribute and return the following information for each occurance of it. The information appears after the attribute as follows:

- Driver Name
- Original Name
- Provider Name
- Driver Version
- Matching Device ID

I would also like the 'device description' to appear first <snip />
imayashi, it appears that the response I offered does exactly what your question asked.

Your question did not ask for:
imyashy wrote:
15 Dec 2023 16:40
the 'Status' to appear below the Device Description.
Which can be very easily be done, and shouldn't have required you ask without trying it!

Code: Select all

%SystemRoot%\System32\pnputil.exe /enum-devices /drivers /class SmartCardReader 2>NUL | %SystemRoot%\System32\findstr.exe /RIC:"^De" /C:"^S" /C:"^  *Driver [NV]" /C:"^  *[OMP]" /C:"^$"


And where it said "each occurance" under "'Matching Drivers'" there was no stipulation for listing only those which were pertinent to 'Installed' drivers only!

So as those things are all new and additional to your initial question, and you did ask for 'Help', my question is what have you done to implement the new requirements yourself. Help is a two way process, it is not a 'you demand' and 'we provide' type of deal.

When you posted a similar question on StackOverflow recently, not only was FindStr mentioned in the comments, (yet you came here without showing any attempt at using it), but I asked some questions which you did not answer. The best solution is not to limit the task to a specific version of a particular application, especially one which requires parsing using language dependent strings.

TBH, your SO question was to determine the inf file for deletion of the driver, so I'd like to know the actual and specific task, the Operating Systems under which it is to be run, and what restrictions may be in place for using other built-in languages and executable programs on the target machine(s).

Re: Help designing a batch file to return driver information

Posted: 17 Dec 2023 17:49
by imyashy
Compo,

Apologies. That is correct, the answer you provided answers the original question. Thank you for that. I should have mentioned that I tested it in my reply.

I'm sure I answered your questions on SO in the comments section of the post. I tested the scripts provided on stackOverflow. One of them worked fine but whilst waiting for an answer to the second script, I searched this forum and found a similar question which provided a script that I thought I could adapt. Aacini helpfully provided a solution.

I don't mean to come across as difficult, I do appreciate all your time and effort here. I only recently discovered pnputil and have been experimenting with it however the scripting is very difficult.Whilst the scripts I previously requested relate to the identification and deletion of a driver package this one is purely about gathering information.

Whilst testing the pnputil command more, I realised that certain peices of information are presented differently when an OEM driver is assigned to a device VS a driver with a compatible ID. I now realise that I missed some key attributes.

For clarification, the actual specific task here is to check what variation of smartcard readers and drivers exist in the estate. There are simply too many machines to check manually hence requesting a more automated method. The plan is to obtain key information about smartcard readers and the corresponding Installed driver and output to a txt file. The users in the estate are using a mixture of windows 10 and 11. There shouldn't be any other restrictions involved apart from group policy restricting admin rights. I don't believe admin rights are required for pnputil read only commands and to output to txt.

The results should exclude any drivers where the 'driver status' does not contain the word 'Installed'. This means that only 1 assigned driver should appear for each device. I've added a fresh set of results from the pnputil command for 2 devices. I've also included an example of how the expected results.


-Device Description
-Instance ID
-Class Name
-Status
- Driver Name
- Original Name
- Provider Name
- Driver Version
- Matching Device ID


New results provided from pnputil

Code: Select all

Microsoft PnP Utility

Instance ID: USB\VID_076B&PID_3031\7&3adb5428&0&1
Device Description: OMNIKEY 3x21
Class Name: SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name: HID Global
Status: Started
Driver Name: oem39.inf
Matching Drivers:
Driver Name: oem39.inf
Original Name: omnikey3x21.inf
Provider Name: HID Global
Class Name SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Driver Version: 12/13/2016 1.0.0.2
Matching Device ID: USB\VID_076B&PID_3031
Driver Rank: 00FF0001
Driver Status: Best Ranked / Installed

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

Instance ID:                USB\VID_076B&PID_3031\7&3adb5428&0&2
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Started
Driver Name:                wudfusbcciddriver.inf
Matching Drivers:
    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Best Ranked / Installed

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked


Expected Results

Device Description: OMNIKEY 3x21
Instance ID: USB\VID_076B&PID_3031\7&3adb5428&0&1
Class Name: SmartCardReader
Status: Started
Driver Name: oem39.inf
Original Name: omnikey3x21.inf
Provider Name: HID Global
Driver Version: 12/13/2016 1.0.0.2
Matching Device ID: USB\VID_076B&PID_3031

Device Description: Microsoft Usbccid Smartcard Reader (WUDF)
Instance ID: USB\VID_076B&PID_3031\7&3adb5428&0&2
Class Name: SmartCardReader
Status: Started
Driver Name: wudfusbcciddriver.inf
Provider Name: Microsoft
Driver Version: 06/21/2006 10.0.19041.1
Matching Device ID: USB\Class_0B&SubClass_00&Prot_00

[/code]

Re: Help designing a batch file to return driver information

Posted: 17 Dec 2023 21:11
by Compo
First of all your results would not be exactly as you posted them, they would be:

Code: Select all

Microsoft PnP Utility

Instance ID: USB\VID_076B&PID_3031\7&3adb5428&0&1
Device Description: OMNIKEY 3x21
Class Name: SmartCardReader
Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name: HID Global
Status: Started
Driver Name: oem39.inf
Matching Drivers:
    Driver Name: oem39.inf
    Original Name: omnikey3x21.inf
    Provider Name: HID Global
    Class Name SmartCardReader
    Class GUID: {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version: 12/13/2016 1.0.0.2
    Matching Device ID: USB\VID_076B&PID_3031
    Driver Rank: 00FF0001
    Driver Status: Best Ranked / Installed

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

Instance ID:                USB\VID_076B&PID_3031\7&3adb5428&0&2
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Started
Driver Name:                wudfusbcciddriver.inf
Matching Drivers:
    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Best Ranked / Installed

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00&Prot_00
    Driver Rank:            00FF2000
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B&SubClass_00
    Driver Rank:            00FF3201
    Driver Status:          Outranked

    Driver Name:            wudfusbcciddriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked

    Driver Name:            UsbccidDriver.inf
    Provider Name:          Microsoft
    Class Name              SmartCardReader
    Class GUID:             {50dd5230-ba8a-11d1-bf5d-0000f805f530}
    Driver Version:         06/21/2006 10.0.19041.1
    Matching Device ID:     USB\Class_0B
    Driver Rank:            00FF3302
    Driver Status:          Outranked


In such situations formatting of the results can make a huge difference.

That said, as there appears to have been an issue with the formatting for your Expected Results you should correct those for us too.

Re: Help designing a batch file to return driver information

Posted: 18 Dec 2023 08:44
by imyashy
If by formatting you mean the indents - they don't matter. I switched the order of the 'Device Description' and ' Instance ID'. If this makes things difficult, happy to have Instance ID first and then Device Description. Essentially the expected results should return the attributes below.

-Device Description
-Instance ID
-Class Name
-Status
Matching Drivers:
- Driver Name
- Provider Name
- Driver Version
- Matching Device ID
- Driver Status


The expected results should look like this:

Code: Select all

Microsoft PnP Utility

Device Description:         	OMNIKEY 3x21
Instance ID:                	USB\VID_076B&PID_3031\5&1487bdb9&0&1
Class Name:                 	SmartCardReader
Status:                     	Started
Matching Drivers:
    Driver Name:            	oem34.inf
    Provider Name:          	HID Global
    Driver Version:         	04/08/2021 2.3.4.121
    Matching Device ID:     	USB\VID_076B&PID_3031
    Driver Status:          	Best Ranked / Installed

Device Description:         	Microsoft Usbccid Smartcard Reader (WUDF)
Instance ID:                	USB\VID_076B&PID_3031\7&3adb5428&0&2
Class Name:                 	SmartCardReader
Status:                    	Disconnected
Matching Drivers:
    Driver Name:            	wudfusbcciddriver.inf
    Provider Name:          	Microsoft
    Driver Version:         	06/21/2006 10.0.19041.1
    Matching Device ID:		USB\Class_0B&SubClass_00&Prot_00
    Driver Status:          	Best Ranked / Installed