Deleting the undeletable on Windows

Recently I rescued a hard drive from and old PC and installed it as a second drive into another one.  I wanted to save some of the files on it, so I didn’t want to wipe it clean, but did want to delete the unneeded Windows folder.  Doing so turns out to be much harder than it should be, even if you’re an Administrator (shouldn’t an Administrator be able to delete every folder that’s not being currently used?).

Came across this blog post, which referenced the exact problem.  I modified the script slightly to also delete the folder in question: I present reallydelete.cmd, just run it as an Administrator and you ought to be able to delete nearly everything you choose (so long as it’s not currently locked by a process):

 

reallydelete.cmd

@echo off
REM	reallydelete.cmd

REM  	Modified from http://blogs.msdn.com/b/tims/archive/2006/11/10/windows-vista-secret-11-deleting-the-undeletable.aspx

REM	Usage: Open an Administrator command prompt and run this, e.g.,
REM	reallydelete C:\path\to\folder
 
echo Taking ownership of %1...
takeown /f %1 /r /d y
icacls %1 /grant administrators:F /t
 
echo Deleting %1...
rd /S /Q %1

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *