How to Find the Driver for a Device in a Batch Script
Knowing which specific driver a piece of hardware is using is a critical task for system diagnostics, troubleshooting, and automated driver installations. You might need to verify that a device is using the correct corporate-approved driver, get the driver version to check if an update is needed, or identify the driver file (.sys) associated with a problematic device.
This guide will teach you how to get detailed driver information using the powerful, built-in driverquery.exe and WMIC command-line utilities. You will learn how to list all drivers and how to filter that list to find the specific driver associated with your hardware.
CRITICAL NOTE: Querying detailed system and hardware information is a privileged operation. For the most complete and accurate results, your script must be run with full administrator privileges.
The Challenge: Linking a Device to a Driver
The Windows Device Manager GUI makes it easy to see a device's properties and its associated driver. To do this from a script, we need a command that can query the same underlying system information. While you can use devcon.exe from the Windows Driver Kit, there are powerful tools already built into Windows.
Method 1 (Recommended): The driverquery Command
The driverquery.exe utility is the standard, built-in tool for listing all installed device drivers and their properties. It is simple, fast, and provides the information in several script-friendly formats.
Command: driverquery /FO CSV
/FO CSV: Formats the Output as CSV (Comma-Separated Values), which is the easiest format to parse in a script.
This produces a detailed list of every driver on the system as output:
"Module Name","Display Name","Description","Driver Type","..."
"amdgpio2","amd_gpio2 Controller","amd_gpio2 Controller","Kernel",...
"amdgpio3","AMD GPIO Controller","AMD GPIO Controller","Kernel",...
"amdpcidev","AMD PCI Root Bus Lower Filter","AMD PCI Root Bus Lower Filter","Kernel",...
"hidusb","Microsoft USB HID Class Driver","HID-compliant mouse","Kernel",...
...
Our goal is to search this list for our target device.
Method 2 (More Advanced): Using WMIC
The WMIC utility can also achieve this by linking two different WMI classes: one for the device and one for the driver. This is more complex but can be more powerful for very specific queries.
Command: wmic path Win32_SystemDriver where "Name='amdgpio2'" get PathName
This is less intuitive than driverquery for general-purpose listing.
Basic Example: Listing All Drivers
This script uses the recommended driverquery command to create a CSV report of all drivers on the system.
@ECHO OFF
SET "ReportFile=%USERPROFILE%\Desktop\Driver_List.csv"
ECHO --- Listing All Installed Drivers ---
ECHO Generating report. This may take a moment...
ECHO Report will be saved to: "%ReportFile%"
driverquery /FO CSV > "%ReportFile%"
ECHO.
ECHO [SUCCESS] Report created.
Parsing the Output to Find a Specific Driver
The most common task is to find the driver for a specific device. You can do this by filtering the output of driverquery with findstr.
Let's find the driver for our network card, which we know is an "Intel(R) Ethernet" device.
@ECHO OFF
SET "DeviceName=Intel(R) Ethernet"
ECHO --- Finding driver for: %DeviceName% ---
ECHO.
REM The /SI switch makes the query "System Information" style, often cleaner.
REM We pipe the output to findstr to get the line for our device.
driverquery /SI | findstr /I "%DeviceName%"
Output:
Intel(R) Ethernet Controller (3) I225-V e2fexpress Kernel
This tells us that the "Intel(R) Ethernet Controller" is using the e2fexpress driver.
Common Pitfalls and How to Solve Them
-
Administrator Rights: For a complete list of all drivers, especially low-level kernel and system drivers, you must run the script as an Administrator.
-
Finding the Right "Device Name": The name you search for needs to match the "Display Name" or "Description" field in the
driverqueryoutput. These are the same names you see in Device Manager. A generic search for "USB" will return dozens of results.- Solution: Be as specific as possible with your
findstrsearch string. It's often helpful to run a fulldriverquery > drivers.txtfirst, and then search that file in Notepad to find the exact name of the device you are interested in.
- Solution: Be as specific as possible with your
-
Getting the
.sysFile Path: Thedriverquery /V(Verbose) switch will show you the full path to the driver's.sysfile on the disk, which is essential for advanced diagnostics.driverquery /V /FO CSV | findstr /I "e2fexpress"
Practical Example: A Network Card Driver Audit Script
This script gets the specific driver name and version for the primary network adapter. This is a common task in a deployment script to verify that a machine has the correct, corporate-approved network driver.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO --- Network Driver Audit ---
ECHO.
REM --- Step 1: Find the name of the primary active network adapter ---
SET "AdapterName="
FOR /F "tokens=4,*" %%A IN ('netsh interface show interface ^| find "Connected"') DO (
SET "AdapterName=%%B"
)
IF NOT DEFINED AdapterName (ECHO No active adapter found. & GOTO :End)
ECHO Found active adapter: !AdapterName!
REM --- Step 2: Find the driver for that adapter ---
SET "DriverInfo="
FOR /F "tokens=*" %%D IN ('driverquery /SI ^| findstr /I /C:"!AdapterName!"') DO (
SET "DriverInfo=%%D"
)
ECHO Driver Info: !DriverInfo!
REM --- Step 3: Get the driver's version from its file ---
FOR /F "tokens=1" %%F IN ("!DriverInfo!") DO (
SET "DriverFile=%%F"
)
FOR /F "tokens=2 delims==" %%V IN ('wmic datafile where "name^="C:\\Windows\\System32\\drivers\\!DriverFile!.sys"" get Version /value') DO (
SET "DriverVersion=%%V"
)
ECHO Driver Version: !DriverVersion!
:End
ENDLOCAL
This is an advanced script that chains multiple commands together to get the final, detailed result.
Conclusion
The driverquery.exe command is the standard and most effective built-in tool for finding and listing installed device drivers from a batch script.
- The core command is
driverquery. Use it with/FO CSVfor the most script-friendly output. - Pipe the output to
findstrto filter the long list and find the specific device you are interested in. - Use the
/Vswitch withdriverqueryto get verbose details, including the path to the driver's.sysfile. - Always run your script as an Administrator for a complete and accurate report.