0X80030021

STG_E_LOCKVIOLATION (0X80030021): The One Fix That Works

This error means Windows can't read a sector because another process locked it. The fix is to close file handles or disable Windows Search indexing.

Quick answer for advanced users

Run handle64.exe -a -p <PID> \Path\To\File from Sysinternals to find the locking process, then kill that process or close the handle. If that doesn't stick, disable Windows Search indexing on the volume via services.msc.

Why does this happen?

This error shows up when you try to read or write a file that's already opened with exclusive access by another process. Windows uses a NTFS lock primitive — if process A opens a file with FILE_SHARE_READ and you try to open it with FILE_SHARE_WRITE or FILE_SHARE_DELETE, you'll get STG_E_LOCKVIOLATION (0X80030021). It's not a hardware fault – it's a software conflict.

The most common triggers: a backup tool (like Veeam or Windows Backup) scanning a drive, a virus scanner holding a file open, or Windows Search trying to index a file while you're copying it. I've also seen this with Dropbox syncing a folder while you try to rename files inside it.

Fix steps

  1. Identify the locking process – Download Sysinternals Handle. Open Command Prompt as admin, navigate to the Handle folder, then run:
    handle64.exe -a -p * \Path\To\Your\File.ext
    Replace the path with your actual file path. If the file is on a drive root, use D:\.
  2. Read the output – Look for a line like pid: 1234 type: File 1B4: \Device\HarddiskVolume3\YourFile.ext. The PID is the process holding the lock. Note it.
  3. Close the handle or kill the process – Easiest: run taskkill /F /PID 1234 (replace 1234 with the actual PID). That terminates the process. If it's a system process you can't kill, use Handle to close just that handle:
    handle64.exe -c 1B4 -p 1234 -y
    The -c flag closes the handle, and -y skips confirmation. This is safer than killing a critical process.
  4. Retry your operation – Copy, move, or delete the file now. If it works, the lock was transient. If it fails again immediately, move to step 5.
  5. Disable Windows Search indexing on the problem drive – Go to services.msc, find Windows Search, right-click, select Properties, set Startup type to Disabled, then click Stop. Apply. This removes the most common persistent lock holder. Then restart your file operation.

Alternative fixes if the main one fails

Check disk for corruption

Sometimes locks don't release because NTFS metadata is corrupt. Run chkdsk C: /f /r from an admin prompt. You'll need to schedule a reboot. This fixes orphaned lock records. I've seen this happen after a sudden power loss.

Use Safe Mode

Boot into Safe Mode with Networking. Many services (like antivirus, backup agents, cloud sync) won't start. You can then delete or move the file without lock interference. Works great for stubborn files.

Unlocker tool

There's a third-party tool called Unlocker (from cedrick-collomb.com). It adds a right-click shell extension. Right-click the locked file, choose Unlocker, and it'll show you what's holding it. It can force-close handles. I'm not a fan of leaving it installed, but it's useful for one-off fixes.

Prevention tip

The most reliable way to avoid this mess: stop letting Windows Search index every damn file on your drive. Disable indexing on drives that don't need it (like external USB drives, archive drives, or large media volumes). Right-click the drive in Explorer, go to Properties > General tab, uncheck Allow files on this drive to have contents indexed. Click Apply, choose Apply changes to drive, subfolders and files. This stops the indexer from ever touching those files, removing the most common lock source.

Related Errors in Hardware – Hard Drives
0X800300FC STG_E_INVALIDNAME (0X800300FC): Fix Invalid Drive Name Error External Drive Asks to Format Every Time — Real Fix 0X00001B5A Fix ERROR_CTX_INVALID_PD (0X00001B5A) on Windows 10/11 0XC01C0019 Fix STATUS_FLT_NO_DEVICE_OBJECT 0XC01C0019 on Backup or Mount

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.