Skip to main content

How to Uninstall a Driver in a Batch Script

Uninstalling a device driver is an important administrative task, often necessary when a driver is causing system instability, when you are replacing a piece of hardware, or to perform a "clean" installation of a newer driver version. While this is typically done through the graphical Device Manager, it can be fully automated from a batch script.

This guide will teach you how to uninstall a driver package from the Windows Driver Store using the modern, standard, and built-in utility: pnputil.exe (Plug and Play Utility). You will learn how to first find the correct "published name" of the driver and then use that name to execute the uninstallation.

danger

CRITICAL WARNING: Uninstalling drivers is a high-risk, low-level system operation. Removing the wrong driver (especially for a storage controller, network card, or chipset) can cause system instability, loss of connectivity, or even prevent Windows from booting. Always have a full system backup and a recovery plan. This script must be run with full administrator privileges.

The Core Command: pnputil.exe

The pnputil.exe utility is the primary, built-in command-line tool for managing the Windows Driver Store. The Driver Store is a secure location in C:\Windows\System32\DriverStore\FileRepository where Windows keeps a collection of all trusted driver packages that have been installed on the system. The pnputil command is the correct way to add and remove drivers from this store.

The Essential Prerequisite: Finding the Driver's "Published Name"

Before you can delete a driver, you must know its unique identifier within the Driver Store. This is called the Published Name (often in the format oem<number>.inf). The best way to find this is to get a list of all third-party drivers.

Command to List Drivers: pnputil /enum-drivers

  • /enum-drivers: Enumerates (lists) all third-party driver packages in the store.

This command produces a detailed list of all non-Microsoft drivers. You need to find your target driver in this list and get its oem##.inf name.

Published name :   oem10.inf
Original name : nv_disp.inf
Provider name : NVIDIA
Class name : Display adapters
...
Published name : oem25.inf
Original name : e2fexpress.inf
Provider name : Intel
Class name : Network adapters
...

From this, you would identify that the NVIDIA display driver is oem10.inf and the Intel network driver is oem25.inf.

The Command to Delete a Driver (/delete-driver)

Once you have the correct oem##.inf name, you can use the /delete-driver switch to remove it from the store.

Syntax: pnputil /delete-driver <PublishedName.inf>

For example, this script uninstalls the NVIDIA display driver we identified as oem10.inf.

@ECHO OFF
REM This script MUST be run as an Administrator.

SET "DriverName=oem10.inf"

ECHO --- Uninstalling a Driver Package ---
ECHO WARNING: This can cause hardware to stop working.
ECHO Target driver: %DriverName%
ECHO.
PAUSE
ECHO.

pnputil /delete-driver %DriverName%

IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] Driver package deleted successfully. A reboot may be required.
) ELSE (
ECHO [FAILURE] An error occurred. The driver may be in use.
)

How to Force the Deletion

Sometimes, Windows will prevent a driver from being deleted if a device is currently using it.

The Error: Deleting the driver package failed: One or more devices are presently installed using the specified INF.

To override this, you can add the /force switch. This will delete the driver package from the store, but the currently installed device will continue to function with the driver until the next reboot.

Syntax: pnputil /delete-driver oem10.inf /force

Key pnputil Parameters Explained

  • /enum-drivers: Lists third-party driver packages.
  • /delete-driver <oem##.inf>: Deletes a driver package.
  • /add-driver <driver.inf>: Adds a driver package.
  • /force: Forces the deletion of a driver package even if it is in use by a device.
  • /reboot: Reboots the system if it is required to complete the operation.

Common Pitfalls and How to Solve Them

  • Administrator Rights: This is the number one cause of failure. You will receive an "Access is denied" error. Solution: You must run the script from an elevated command prompt ("Run as administrator").

  • Deleting In-Box Drivers: pnputil is designed to manage third-party drivers. It will generally prevent you from deleting the generic drivers that ship with Windows.

  • Driver is in Use: As mentioned, the command will fail if the driver is in use. Solution: For a clean uninstall, the best practice is to first uninstall the device itself from Device Manager, and then run pnputil /delete-driver. For a scripted solution, use the /force switch and then plan for a reboot.

Practical Example: A "Clean Reinstall" Script for a Network Driver

This script automates the process of completely removing an old network driver before installing a new one.

@ECHO OFF
SETLOCAL
REM This script MUST be run as an Administrator.

SET "ProviderName=Intel"
SET "NewDriverInf=C:\Drivers\New_Intel_LAN\e2fexpress.inf"

ECHO --- Clean Reinstall of Intel Network Driver ---
ECHO.
ECHO Step 1: Finding the old Intel LAN driver package...

REM --- Find the 'oem##.inf' name for the current driver ---
SET "OldDriver="
FOR /F "tokens=2 delims=:" %%A IN ('pnputil /enum-drivers ^| findstr /I "Original name" ^| findstr /I "e2fexpress.inf"') DO (
FOR /F "tokens=2 delims=:" %%B IN ('pnputil /enum-drivers ^| findstr /B /C:"Published name" -A 1 ^| findstr /I "oem"') DO SET "OldDriver=%%~B"
)
FOR /F "tokens=*" %%N IN ("%OldDriver%") DO SET "OldDriver=%%N"


IF NOT DEFINED OldDriver (
ECHO [INFO] No old driver package found.
) ELSE (
ECHO Found old driver: %OldDriver%. Uninstalling it...
pnputil /delete-driver %OldDriver% /force
)

ECHO.
ECHO Step 2: Installing the new driver...
pnputil /add-driver "%NewDriverInf%" /install

ECHO.
ECHO --- Operation Complete ---
ECHO A reboot is recommended to finalize the installation.
PAUSE
ENDLOCAL
note

The FOR /F logic to find the driver is complex; this is an advanced script.

Conclusion

The pnputil.exe command is the modern and definitive tool for scripting the uninstallation of driver packages from the Windows Driver Store.

For a successful and safe operation:

  1. Always run your script as an Administrator.
  2. Use pnputil /enum-drivers first to find the exact Published Name (e.g., oem##.inf) of the driver you want to remove.
  3. Use the command pnputil /delete-driver <PublishedName.inf> to remove the driver.
  4. Use the /force switch if you need to remove a driver that is currently in use by a device, and plan for a reboot.