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
- Identify the locking process – Download Sysinternals Handle. Open Command Prompt as admin, navigate to the Handle folder, then run:
Replace the path with your actual file path. If the file is on a drive root, usehandle64.exe -a -p * \Path\To\Your\File.extD:\. - 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. - 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:
Thehandle64.exe -c 1B4 -p 1234 -y-cflag closes the handle, and-yskips confirmation. This is safer than killing a critical process. - 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.
- 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.