Windows Vista Secret #11: 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 / secret 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. But I'm the purist type who hates even the thought of leaving any detritus around and insists upon a clean install to a pure, unsullied partition.
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. For example, on my home machine, I switched the C: and D: drive cables around and installed Windows Vista RTM on the new drive. Having tested everything worked, I wanted to delete some old redundant directories (like the old \Program Files directory). If even an administrator can't access the file, 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 takeown (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.
These two lines have saved me a lot of pain over the last week as I've gradually flattened and reinstalled the RTM version of Windows Vista on each of my machines: hopefully they'll be equally useful to you!
Comments
Anonymous
November 10, 2006
Tim Sneath provides two commands all IT persons should keep in their toolbox: takeown and icacls.Anonymous
November 10, 2006
Thanks very much! That problem plagued me with a couple of foldersAnonymous
November 11, 2006
Awesome tip. Thanks Tim.Anonymous
November 12, 2006
Well it has been a long, long, difficult project, but come tomorrow around 8:30 my time, all of my longAnonymous
November 16, 2006
Hey, very nice! Is it perhaps possible to put this bath file in the Windows catalog and create a option "All your vase are belong to us" in the right-click drop-down menu using the same regedit actions as in WinXP?Anonymous
November 24, 2006
I appreciate these tips, but when you click on the "secret" tag, the server only returns secret number 8 through 11. Where are the rest of these "secrets"? What is the point of numbering & tagging these posts if you don't apply the tags in a uniform way? :-]Anonymous
November 27, 2006
Where are these commands located? I don't see them on my system. ThanksAnonymous
November 29, 2006
I ran into a situation where I needed access to my Program Files folder located in my first partitionAnonymous
December 11, 2006
Since when Micosoft decide what I can delete from my personal HDD and what not. Who do you think you are? Is my HDD and if I wand I can delete everythink! Why don't you use yours brains and make different security options acording with everybody needs?Anonymous
December 12, 2006
介绍如何在Vista中删除老系统遗留下来的文件Anonymous
December 18, 2006
By now I hope that most of you have atleast tried Vista. If not, join the bandwagon . INSTALL VISTA!!!Anonymous
December 20, 2006
原文地址:http://blogs.msdn.com/tims/archive/2006/11/10/windows-vista-secret-11-deleting-the-undeletable....Anonymous
December 29, 2006
Very handy. Thanks you!Anonymous
January 19, 2007
Thank yoiu very much for this solution. Prior to this, I had to rethink other solutions due to this barrier.Anonymous
February 06, 2007
I just did a fresh install of Vista Ultimate on my home desktop PC. The install all went fairly smoothAnonymous
September 23, 2007
I ran into a situation where I needed access to my Program Files folder located in my first partitionAnonymous
January 03, 2008
[Vista] Cancellare file lockatiAnonymous
August 19, 2008
1:如何删除删不掉的文件 来源:http://blogs.msdn.com/tims/archive/2006/11/10/windows-vista-secret-11-deleting-th...Anonymous
October 20, 2008
Bonjour tout le monde !!! :) Voila maintenant un long moment que je n'avais rien posté comme message ici :) Et je fais mes plus plates excuses à ceux qui attendaient des nouvelles par le biais du BDM ...