Deleting the Undeletable

As many of us move forward from Windows XP or prior beta versions of Windows Vista to the final RTM version, I thought this little tip might be in order. You may be aware that Windows Vista includes a number of different ways to upgrade a computer, from a straight in-place upgrade (insert CD, run setup and choose upgrade) to Windows Easy Transfer, which allows you to copy settings, programs and data from an old setup a fresh shiny new OS environment. In doing this, it's not unusual to find some folders that can't be accessed, even by an administrator, because their ACLs were set for accounts with SIDs that applied to an old partition.

How do you take it back? -> The secret lies in two command-line utilities, one ancient, the other completely revised for this release. Respectively, these are take own (which takes ownership of a file or directory) and icacls (which sets new ACLs on that directory). I created a small batch command on my system called itsmine.cmd, as follows:

takeown /f %1 /r /d y
icacls %1 /grant administrators:F /t

From an elevated command prompt, you can run a command such as itsmine D:\hard_to_delete and this will reset ownership and ACLs on the hard_to_delete directory such that a command like rd /s D:\hard_to_delete should work.