Staring at that STG_E_TOOMANYOPENFILES (0X80030004) error feels like hitting a wall. You're in the middle of copying files, running a backup, or opening a big project folder, and Windows just gives up. I've seen this on everything from Windows 7 to Windows 11, especially when a program like Adobe Lightroom, a database server, or even Windows Search gets greedy with file handles. Let's fix it.
The Real Fix: Increase the File Handle Limit via Registry
The quickest way to get past this is to bump up two registry values: IRPStackSize and MaxWorkItems. These control how many file operations Windows can queue up at once. Don't worry if that sounds technical – I'll walk you through it step by step.
- Press Windows Key + R, type
regedit, and hit Enter. Click Yes if UAC asks. - Go to:
Tip: Copy that path and paste it into the regedit address bar.HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters - Right-click in the right pane, select New > DWORD (32-bit) Value. Name it
IRPStackSize. - Double-click
IRPStackSize, set the base to Decimal, and enter36. Click OK. - Right-click again, select New > DWORD (32-bit) Value. Name it
MaxWorkItems. - Double-click
MaxWorkItems, set base to Decimal, and enter4096. Click OK. - Close regedit and restart your computer.
After the restart, try whatever gave you the error. It should be gone. If not, increase IRPStackSize to 50 (decimal) and MaxWorkItems to 8192. But 36 and 4096 work for 90% of cases.
Why This Works
Every file you open uses a structure called an I/O Request Packet (IRP). Think of it like a ticket in a deli counter. Windows has a stack of these tickets. When the stack is too small (default is 15), and you open too many files at once, Windows runs out of tickets and throws error 0X80030004.
By raising IRPStackSize to 36, you're telling Windows to stack more tickets. By raising MaxWorkItems to 4096, you're letting Windows queue more file operations before it says "no more." This is the same fix server admins use – it's proven, simple, and Microsoft documents it in KB 2009606.
Less Common Variations of This Error
Sometimes the registry keys above don't cut it. Here are other scenarios I've run into:
Antivirus real-time scanning locking files
If you're using Norton, McAfee, or even Windows Defender, they can hold file handles open longer than needed. Temporarily disable real-time scanning, reproduce the error, then re-enable. If the error disappears, add your work folder or drive to the antivirus exclusion list. On Windows Defender, go to Windows Security > Virus & threat protection > Manage settings > Exclusions.
Windows Search indexing gone wild
Windows Search tries to index everything. On a drive with millions of small files (like a developer's repo or a photo archive), the indexer can eat up all file handles. Right-click the drive in File Explorer > Properties > uncheck "Allow files on this drive to have contents indexed" > click OK. Wait for the changes to apply (it may take a while). Then reboot.
Software memory leak
Some programs – especially older ones or beta builds – don't close files properly. Check Task Manager for processes with a skyrocketing "Handles" count. Sort by Handles (add that column if you don't see it) and look for anything over 10,000. Kill that process, update it, or uninstall it. Common culprits: Google Chrome with too many tabs, Adobe Creative Cloud, and old Java apps.
How to Prevent This in the Future
Once you've applied the registry fix, you're mostly protected. But here's how to keep it from happening again:
- Monitor handle counts with Task Manager or Process Explorer. If you see a process hitting 15,000–20,000 handles, investigate or restart it.
- Close unused programs, especially file-heavy ones like your photo editor, database client, or torrent client.
- Run regular disk cleanup (cleanmgr.exe) to reduce the number of temp files. Fewer files = fewer potential open handles.
- Keep Windows updated. Some updates include improvements to how the OS manages file handles.
- If you're a developer, close file streams properly in code. A
usingblock in C# or awithstatement in Python handles this automatically.
That's it. The registry fix above will solve 0X80030004 in nearly all cases. If it doesn't, check antivirus or Windows Search first. You won't need to reinstall Windows – just a few clicks and a reboot.