HOW TO: Delete an Undeletable or Locked File
June 4, 2007 by Kiltak |
Have you ever run into a situation where you wanted to delete a file, but Windows simply wouldn’t allow you to do it? Personally, these things happen to me all the time, especially when I’m at a client’s house trying to get their machine clean of malware. Have you ever tried deleting a locked file using common windows commands? If so, then you’ll know that this is just not possible.
The main reason behind this is that the explorer.exe process locks files that are in use, effectively preventing you from deleting them. Usually, these files should not be touched, but sometimes, situations arise when you really need to erase some troublesome ones.
Fortunately, there are a few easy solutions to delete those files.
Solution #1: Kill explorer.exe
- Open a command prompt
- Navigate to the location where the locked file is
- Press CTRL-ALT-DEL, click on “task manager”, select the Processes tab
- Kill the explorer.exe process via the “End Process” button
- Go back to the command prompt and delete the file
- Bring up the task manager windows again
- Select file->new task
- Type explorer.exe in the “create new task” field
- Press OK.
Solution #2: Use The Windows Recovery Console
Just stick your Windows CD in your CD tray, boot on it, and at the “Welcome to Setup” screen, press “R“. Once the recovery console has started, navigate to the location of your locked file, and delete it. Since WRC does not really start the system, the files will not be in use, and you will be able to delete them
Solution #3: Use unlocker
Unlocker is a very useful freeware that will allow you to unlock any files that are currently in use by Windows. You’ll know if this is happening if you are getting any of these messages when trying to delete a file:
- Cannot delete file: Access is denied
- There has been a sharing violation
- The source or destination file may be in use
- The file is in use by another program or user
- Make sure the disk is not full or write-protected and that the file is not currently in use
Unlocker will make things right again for you.
You’ll notice that right after installing the software, a new option named “unlocker” will appear when right clicking any files or folders in Windows Explorer. To unlock a locked file, just right click it, select unlocker, and the unlocker software will start. Then, click “unlock all” and close the software. Now that your file is unlocked, just delete it in Windows Explorer, as you always do. This is much simpler than solution #1 or #2, isn’t it?
I hope these three solutions will help you get rid of those hard to delete files. If you’ve got any additional suggestions, the comment section is open for your comments!
You Might Also Like:
- Articles and Reviews
- Exchange 2003 transaction log files filling up very quickly
- Ctrl + Alt + Del: The History
- WP-Cache plugin for Wordpress problems
Subscribe by Email












that should have said “sudo rm <filename>”
Now let’s hope that worked.
I think the purpose is to save having to reboot.
Even if you boot in safe mode or select “command prompt only”.. the file will be locked.. that’s when these techniques come in handy.
Now you can delete it.
permissions are different in cmd. rename the file. then delete the renamed file. works about 80% of the time. after that you can go to the more labour intensive solutions.
But why mess with all that for the easy ones?
If anyone has a quick and dirty cure for those damn things, I’ll bake you a pie!
BTW even if the file is locked by Windows Explorer you don’t have to restart - simply kill Explorer in the Task Manager and run it again.
Greets
if there is a file you cannot delete
open the command prompt go to the folder that it is in,
type
cacls /t /p everyone:n
then hit enter it will tell you it processed the file then reboot the computer and you will be able to delete it.
you can cacls as many files as you want before the reboot.
all this does is lockdown the file so that it cant start after reboot.
Non command line file deletion w/o using explorer:
Open taskmanager>kill explorer>run: iexplore \>browse for file and delete it>run explorer
really thnx!
I have a very tricky piece of spyware that attached itslef to explorer.exe and winlogon.exe
It’s not a problem to unlock it from explorer, but if winlogon.exe is killed, the computer shuts down immediately. I tried using unlocker, but like I said, the computer just shuts down immediately.
Any other suggestions?
Any help????
and then drag this new file and overwrite the corrupted file. this solution also works sometimes with files that windows won’t let you delete or move from one folder to another.
I had two files on my server (w2k3) which, if I tried to do ANYTHING with (right click, hover over, delete, view properties - even del through cmd) it would BSOD! I’d tried serveral repair tools to no avail.
Who would have thought that just copying a non-corrupt file over the top would work!!! It did though, and thank you soooo much
Joff
(sorry for using so many exclaimation marks btw)
Be careful thou, It changes the access rights to the file.
Try:
c:\cacls “” /e /g :F
is fully qualified path. e.g “c:\windows\afile.sys”
is you windows username.
To Reset the permisions try:
These are all the switches for the CACLS command
/t Think of the ‘t’ as meaning trash the original security permissions.
/e Think of the ‘e’ as CACLS inviting you to edit. Alternatively think of ‘e’ for append or correct one that went wrong.
/g This is the main switch, ‘g’ means grant; as in: grant me the permissions. This switch requires a user, followed by a colon and letter for the permission. Here are two examples:
/g guyt:f full control for guyt.
/g freddy:r read only for freddy.
/p Almost the same as /g. CACLS /p replaces where as /g appends.
/r Revokes, removes a named user from the Access Control List. Classic usage would be /r users.
/d ‘d’ stands for deny. Remember that if deny the users group the result is that nobody is able to see the files, so use /d sparingly.
/c ‘c’ is for continue. This switch works for CACLS like, ‘on error resume next’ works in VBScript. Adding /c says to CACLS, ‘Carry on despite an error’.
Be careful !!
Maybe someone can explain this to me. The article is written in English; therefore, it follows that posting a (relevant) response to it shows that you know English. If you know English and are replying to an article written in English, what makes you decide to use another language?
i wanna ask u somthin just for the blogger.com ..
if can we setup blogger blog locally on our windows system…..on windows xp …..just for d testing prupose ..
b4 making any online changes i wanna see dt on my system…
or is there any book to read for …or any other kinda help will be appreciated …..
thanks alot for being a geek dts so sexy …..
take care
mukarram
Some crappy Curtis MP3 software driver created the folder and file, I guess they were trying to keep it from accidental deletion or the installer was just buggy.
Who ever posted putting in the Win cd hit R and go to the recovery console and delete the file worked just fine.(Kiltalk I think) Thanks for that info…cool site, I’m glade I found my way here
Thanks Again, Peace
so anyone got an idea of where i should start with this? it seems to change filenames every so often. i have used unlocker when i needed to get rid of malware so i figured this was the place to ask.
Although there may be other means, I like the approach:
* shut the system down
* boot CD/DVD of a different operating
system - e.g. Knoppix, Ubuntu, etc.
* mount the applicable filesystem(s) rw
* change attributes on the file(s) if
necessary
* delete (rm(1)/unlink(2)) the file(s)
* unmount the filesystem(s)
* you’re done (reboot you DOS/windows, if
you really want)
The article also didn’t cover “undeletable” files on other operating systems.