Saturday, February 16, 2008

Vista: Access denied error while trying to delete files

Sometimes in Microsoft Vista, simple tasks such as deleting files is not an easy thing! After my gateway system crashed I created a backup and restored with the Gateway Recovery Center. It worked great. All the files of of system, including the Windows directory, were backed up under C:\Backup. After picking through my old user files and moving them to the new install I was then ready to delete all the useless C:\Backup files as they were taking up about 20gb of space! However, whenever I tried to delete the files I got a "Access Denied" error. After hours of trial and research here is what worked for me.

I took ownership of the files . Using the link is easiest and shows you how to create a registry key and take ownership of the files through a simple shift + right click menu. Deleting the files was possible after I ran this however I did have to run it twice on stubborn files that did not want to delete. Also, run the command on a single folder instead of multiple-selecting folders because you will have to click Vista's lovely "continue" prompts for each folder.

If you don't want to install something permanently in your registry you could also use the command like to do this. You have to use the takeown and icacls commands. Make sure you start the command window with "Run as Administrator" or you will run into problems.

Here are the commands to use:
  • takeown /f "C:\yourdirectory\" /r
  • icacls "C:\yourdirectory" /grant administrators:F
If you get error messages and need to chose Skip then retry the commands on the subfolders until all the files are deleted.

In certain cases on you may get a "Destination Folder Access Denied". You can get around this by holding Shift while you drag the folder to the Recycle Bin. This will delete the files directly without moving them to the Recycle Bin.

1 comment:

Unknown said...

Try " Long Path Tool " is also useful in situations where you see these error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.