Home > database >  I want to run Driverquery /v from a script
I want to run Driverquery /v from a script

Time:11-29

I want to run Driverquery /v from a script and from the result obtained, I want to select a particular column's value based on a specific row value which is a string.

I have written this driverquery /v in my batch file, and ran the batch file, it was able to list the driver results and their path, but do not know how to proceed from there?

CodePudding user response:

I will give you two options to solve this problem

Use the quote as a delimiter

for /f tokens^=26^ delims^=^" %%G in ('driverquery /V /FO CSV ^|findstr /IC:"Virtual WiFi Miniport"') do echo %%G

Create an array of variables from the output. In your case the variable x14 will be the field you are looking for.

for /f "delims=" %%G in ('driverquery /V /FO CSV ^|findstr /IC:"Virtual WiFi Miniport"') do set "x=%%~G"

set i=1
setlocal enabledelayedexpansion
set "x!i!=%x:","=" & set /A i =1 & set "x!i!=%"
set x

EDIT: A third option

REM OPTION 3 use the Driver Query header row as variables
for /f "delims=" %%G in ('driverquery /V /FO CSV') do (set "vars=%%~G" & GOTO NEXT)
:NEXT
REM Cleanup variable names
SET "vars=%vars: =_%"
SET "vars=%vars:(=_%"
SET "vars=%vars:)=%"
SET "vars=%vars:path=dPath%"
SET "vars=%vars:","= %"

for /f "delims=" %%G in ('driverquery /V /FO CSV ^|findstr /IC:"Virtual WiFi Miniport"') do set "str=%%~G"

set "p=%%"
set "v=%vars: =" & set "s=!str:*","=!" & call set "!v!=!p!str:","!s!=!p!" & set "str=!s!" & set "v=%" & set "!v!=!s!"

REM Display all the values
FOR %%G IN (%vars%) DO CALL ECHO %%G = %%%%~G%%

CodePudding user response:

Here's what I would call a simpler way of achieving your intended goal, (despite it being deprecated), use .

The following should identify the 'DriverQuery' Path: relating to a 'DriverQuery' Display Name: which contains the string Virtual WiFi Miniport

:

For /F Tokens^=^6^ Delims^=^" %G In ('%SystemRoot%\System32\wbem\WMIC.exe SysDriver Where "DisplayName Like '%Virtual WiFi Miniport%'" Get PathName /Format:"MOF" 2^>NUL') Do @Echo %G

If you're wanting the string to be defined as a variable for later use, then use a :

@For /F Tokens^=^6^ Delims^=^" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe SysDriver Where "DisplayName Like '%%Virtual WiFi Miniport%%'" Get PathName /Format:"MOF" 2^>NUL') Do @Set "DriverPath=%%G"
  • Related