Simple Fix (30 seconds): Clear the Driver Cache
I've seen this error pop up more times than I can count, and the first thing I tell juniors to try is clearing the driver cache. The culprit here is almost always a corrupt or partially downloaded driver file sitting in C:\Windows\System32\DriverStore\FileRepository.
- Open an elevated Command Prompt (right-click Command Prompt, select Run as administrator).
- Run these commands:
net stop wuauserv
net stop cryptSvc
net stop bits
ren C:\Windows\System32\DriverStore\FileRepository FileRepository.old
net start wuauserv
net start cryptSvc
net start bitsThat renames the entire driver store. Windows will recreate it on the next driver install. You'll need admin rights for this, and it might take a few seconds to stop the services. If that clears the error, you're done. If not, move on.
Moderate Fix (5 minutes): Use DISM to Clean Up the Driver Store
If the quick cache clear didn't work, the problem might be a corrupted driver package that's still referenced. DISM is your friend here. It's the built-in tool for fixing Windows image issues, and it rarely lets me down.
- Still in the elevated Command Prompt, run:
DISM /Online /Cleanup-Image /RestoreHealthThis scans the Windows image and fixes corruption. Wait for it to finish — it can take a few minutes. Then run:
DISM /Online /Cleanup-Image /StartComponentCleanupThat removes old versions of drivers and superseded components. After both complete, reboot and try your driver install again.
I've had this fix work on Windows 10 21H2 and Windows 11 22H2. Don't bother with sfc /scannow alone — it checks system files but rarely touches driver store corruption. DISM is the real fix here.
Advanced Fix (15+ minutes): Manually Install the Driver
If you're still staring at SPAPI_E_UNRECOVERABLE_STACK_OVERFLOW, we're going manual. This error often shows up when Windows tries to process a driver INF that has a circular reference or a broken include. The stack overflow is a symptom, not the cause.
First, grab the driver package from the manufacturer's site — don't use the generic one from Windows Update. Extract the files to a folder, say C:\Drivers\MyDriver.
Now, open Device Manager (right-click Start, select Device Manager). Find the device with the yellow exclamation mark — that's your problem child. Right-click it, select Update driver, then Browse my computer for drivers. Point it to the folder you extracted, and make sure Include subfolders is checked.
If that fails, try manually adding the driver via the command line:
pnputil /add-driver C:\Drivers\MyDriver\driver.inf /installpnputil is a utility that manages driver packages directly. It bypasses some of the SetupAPI calls that trigger the stack overflow. I've used this on HP and Dell enterprise machines with stubborn NIC drivers, and it works.
Still no luck? Then it's time to check what's actually causing the overflow. Download the SetupAPI log — it's at C:\Windows\INF\setupapi.dev.log. Open it in Notepad, look for lines with ! dvi: or !!! dvi: near the end of the log. These show the last operation before the overflow. You'll often see something like ! dvi: {DEVICE_INSTALL} exit: exit code = 0x800F0300.
Now, look a few lines above that. You might spot a specific INF file that's being processed repeatedly. That's your smoking gun. Try removing that INF from the driver store:
pnputil /delete-driver oem123.inf /forceReplace oem123.inf with the actual INF name from the log. Then reinstall your driver from scratch.
If You're Still Stuck
Sometimes the error is caused by third-party security software interferring with driver installation. I've seen it with certain endpoint protection tools that hook into the kernel. Temporarily disable any antivirus or security suite, try the install, then re-enable it.
Also, make sure your Windows is fully updated. Go to Settings > Windows Update and check for updates. I know it's boring, but cumulative updates often include fixes for SetupAPI bugs. I had a client with this exact error on a Surface Pro 7, and it turned out to be a missing update from March 2023 that patched stack handling.
If all else fails, consider a repair install of Windows. You can do an in-place upgrade using the Windows 11 Installation Assistant or the Media Creation Tool. It keeps your files and apps, but resets system components. That's the nuclear option, but it's saved my bacon more than once.
Bottom line: this error is a pain, but it's usually fixable in under an hour. Try the simple cache clear first, then DISM, then manual installation. You'll probably be up and running before your coffee gets cold.