I know of two different reasons that Windows may prevent you from
deleting a file. The first reason is that a process has an open
handle to the file. The second is that you don't have correct
ownership/permissions to delete the file.
The first reason can often be resolved by simply rebooting to remove
the process that has the open handle. If the process is one that is
launched automatically during boot or login (say a virus scanner), the
reboot method may not work. The next step is to get
Process Explorer from Sysinternals. Install Process Explorer and
run it. Then use it to search for file handles to the file you want
to delete. When you find the handle, close the handle and try to
delete the file before the process can open the handle again. You may
also try renaming the file before closing the handle.
If you can't find any open file handles to the file you want to delete,
then the ownership and/or permissions of the file may be blocking you.
You will need to have administrator priviledges to resolve this issue.
If you have several files with this issue, then fixing the ownership
and permissions becomes a lot of work. I recomend running cmd.exe as
administrator and using one of the following scripts instead. They
use commands to take ownership, get full administrator access to the
file, and then delete the file. Be sure you know what you are
deleting as you cause major problems to your system by deleting the
wrong files. The nukefile script will delete the file you specify and
the nukedir script will delete the specified directory and all its
subdirectories. Simply download the script you want and rename the
script to remove the .txt extension. The file now will have a .cmd
extension. Just follow the name of the script with the name of the
file or directory you want to delete.
nukedir.cmd.txt example: > nukedir MyDirToBeDeleted
nukefile.cmd.txt example:
> nukefile MyFileToBeDeleted