Delete Locked Files Windows: 6 Ways That Work
In this article
If Windows says a file is open in another program and won't let you delete it, the fix is to find and close the program holding it, or use a built-in tool that forces the deletion safely. This article explains why files get locked and gives you six reliable methods to remove them, from restarting Explorer to using the Command Prompt.
Why Windows Locks Files
Windows locks a file when a process has it open, even if you don't see a window. This is normal for files in use by the system, but it becomes a problem when a program crashes or a background process hangs onto a file you want to remove. Common culprits include:
- Windows Explorer previewing a photo or video
- Antivirus scanning a downloaded file
- Media players holding a music or video file open
- Office programs keeping a document in the background
- Cloud sync clients (OneDrive, Dropbox) syncing a file
The error message usually names the program, but sometimes it just says "The action can't be completed because the file is open in another program."
Method 1: Close the Program Holding the File
The simplest fix is to close the program that has the file open. Check the system tray (the arrow near the clock) for hidden apps, and close any preview panes in File Explorer. If you don't know which program it is, use the built-in tool:
- Press Ctrl+Shift+Esc to open Task Manager.
- Look under Processes for anything that might use the file (e.g., Word, VLC, Photoshop).
- Right-click the process and select End task.
- Try deleting the file again.
If that doesn't work, restart Windows Explorer (the process that manages the desktop and file windows). In Task Manager, find Windows Explorer, right-click it, and choose Restart. This releases locks from preview thumbnails and folder views.
Method 2: Use the Command Prompt to Force Delete
If closing programs doesn't help, you can use the Command Prompt to delete the file directly. This bypasses some locks because it doesn't go through Explorer.
- Press Win + R, type
cmd, and press Ctrl+Shift+Enter to run as administrator. - Type
del /f /q "C:\full\path\to\file.ext"and press Enter. - For a folder, use
rmdir /s /q "C:\full\path\to\folder".
The /f flag forces deletion of read-only files, and /q suppresses confirmation prompts. If the file is locked by a system process, this may still fail, but it works for many cases.
Method 3: Use Safe Mode to Delete
Safe Mode starts Windows with only essential drivers and services, so most third-party programs won't run and won't lock files. This is the most reliable built-in method for stubborn files.
- Hold Shift and click Restart from the Start menu.
- Choose Troubleshoot → Advanced options → Startup Settings → Restart.
- Press 4 or F4 to enter Safe Mode.
- Navigate to the file and delete it normally.
If you can't delete it even in Safe Mode, the file may be protected by Windows itself (e.g., system files) and you should not force it.
Method 4: Use a Third-Party Unlocker Tool
Tools like LockHunter or IObit Unlocker integrate with the right-click menu and show which process is locking a file. They can unlock and delete it with one click. These are free for personal use and are generally safe, but always download from the official website. They work by terminating the locking process or scheduling deletion on reboot.
If you prefer not to install software, you can use Microsoft's own Process Explorer (from Sysinternals) to find the handle, but that's more advanced and not necessary for most users.
Method 5: Schedule Deletion on Reboot
If a file is locked by a service that starts with Windows, you can schedule it to be deleted before that service loads. Use the Microsoft Management Console (or simply use the pending file rename operations registry trick, but that's risky). A safer built-in way is to use the Task Scheduler to run a delete command at startup:
- Open Task Scheduler from the Start menu.
- Create a new task that runs at logon.
- Set the action to
cmd.exewith the argument/c del /f /q "C:\path\to\file". - Run the task manually after rebooting.
This is overkill for most users, but it works when nothing else does.
Common Mistakes and Misconceptions
Mistake: Trying to delete a file that's actually a system file. Windows protects essential files like win32k.sys or pagefile.sys. Forcing deletion can corrupt Windows. If the file is in C:\Windows and you didn't create it, leave it alone.
Mistake: Using a file shredder to "unlock" files. Shredders overwrite data, but they don't unlock files. They'll just fail with the same error.
Misconception: You need to disable antivirus to delete files. Antivirus can lock files during scanning, but disabling it entirely is risky. Instead, pause real-time protection temporarily, delete the file, then re-enable it.
Frequently Asked Questions
Q: Why does Windows say the file is open in another program when it's not?
A: The program may be running in the background without a visible window. Check the system tray and Task Manager for processes like "dllhost.exe" or "SearchHost.exe" that might be indexing or previewing the file.
Q: Can I delete a locked file by renaming it first?
A: Sometimes renaming works if the lock is on the file's content, not its name. Try renaming the file and then deleting the renamed copy. If renaming also fails, the lock is on the file itself.
Q: Is it safe to force delete a file with a third-party tool?
A: Generally yes, if the tool only terminates the process that has the file open. But if the file is a system file or is being used by a driver, force deletion can cause instability. Always check what the locking process is before killing it.
Q: What if the file is locked by a virus?
A: If you suspect malware, don't try to delete the file manually. Run a full antivirus scan first. Malware often locks itself to avoid removal, and deleting it without cleaning the infection can leave your system vulnerable.
Q: Does restarting the computer always unlock files?
A: Not always. Some programs (like cloud sync clients) automatically reopen files on startup. If a file is locked after reboot, check startup programs and disable the one that's holding it.
Q: Can I delete a locked file from another user account?
A: Yes, if you have administrative rights. Log into a different admin account and try deleting the file. The lock is tied to the user session, so another account may not have the same lock.