Force file deletion on Windows
Often on my development workstation (on which I am administrator and the only user), I am unable to delete files by deleting the root folder - despite having recursively taken ownership of the tree. I am presuming that this is due to the file being locked by another process.
What (scriptable) options do I have that can help here?
Comment: I should have also said that I'm on 2008 x64.
Solution 1:
You could use LockHunter to see which process is blocking the deletion of a file. It's a freeware tool for Windows (32 bit and 64 bit versions available) which integrates itself into the Windows Explorer context menu.
It is a free tool to delete files blocked by something you do not know. LockHunter is useful for fighting against malware, and other programs that are blocking files without a reason. Unlike other similar tools it deletes files into the recycle bin so you may restore them if deleted by mistake.
(source: lockhunter.com)
Solution 2:
With MoveFile from Sysinternals you can schedule the deletion for next reboot or you could try to unlock the file with Unlocker.
Solution 3:
I posted this on this thread. Basically I use Systernal's Process Monitor to see what's locking the file. This How-to is great on how-to use it for this purpose.