Delete an undeletable file in Windows

I found a folder named with random sequence of digits and letters like 4b64f439c26281ab01b0a9ce. With contents cleary suggesting that this is some kind of garbage left by some installation process, most likey Windows Update or some core Windows driver update.

Many attempts to delete this folder, including this one failed, so I had to come with my own solution.

The fastest way

From mydigitallife.info comes the quickest solution with using command-line (run cmd.exe as an admin):

For files:

cd <folder>
takeown /f <filename>
icacls <filename> /grant administrators:F

Where:

  • <folder> is a full path to directory holding file, you want to delete or take ownership of
  • <filename> is questioned file name

Note, that original article has takeown /f <filename> /d y in second line, which was not working in my case, throwing some errors. Executing just takeown /f <filename> was enough.

For folders command sequence is very similar, only this time all actions will be performed recursively:

takeown /f <folder> /r /d y
icacls <folder> /grant administrators:F /t

Again, if takeown /f <folder> /r /d y fails, then try to use just takeown /f <folder> /r or just takeown /f <folder>. You can also remove the /r (from takeown) and /t (from icacls) switch to prevent the task been perform recursively.

For both solutions (for taking over files or folders) if you’re assigned to other user account or group than default administrators group, change administrators to the desired user name or group name accordingly.

This solution does not work in every situation, so follow to other solutions presented below.

The clickable way

This solution shows you, how you can gain permissions or take ownership of file or folder by clicking through endless number of windows and prompts. It is quite hard at the beginning, but can come handy at some point.

The thing, you need to know, is that Windows will do the best, to make you deleting such folder as hard as possible! As you can see on mentioned page, solution consists of five steps and nearly twenty points on check list. In my case, solution was quite different (given below), but still you have to reserve some time for this process, so don’t get your hands on this, if you have about a minute or so.

All right, let’s get to work.

I skip first part given in cited solution, as I assume, that you already have an administrator account enabled, you’re logged in and since you still can’t delete that damn folder, your frustration rises. Let’s get to second part. Remember, that you can start doing these things on root folder (i.e., the one you actually want to delete), but this will most likely fail, and you’ll have to start the entire job from changing properties and deleteing first of all subfolders in root folder.

Let’s start with changing owner of a folder:

  1. Right-click the folder, you want to delete. Go to the Security tab. Click the Advanced button at the bottom.
  2. In newly opened another window, go to the Owner tab and click the Edit button below the list.
  3. In third opened windows, check, if you have YOURACCOUNTNAME (YOURCOMPUTERNAMEYOURACCOUNTNAME) placed on list titled Change owner to. If not, reffer to Step 3.d in this article.
  4. Select YOURACCOUNTNAME (YOURCOMPUTERNAMEYOURACCOUNTNAME) on that list.
  5. Check Replace owner on subcontainers and objects checkbox to force Windows to propagate all changes.
  6. Click OK four times, to close all opened windows and to confirm, that you know, what you’re doing.

We’re talking about the account you’ve just logged in with (it, of course, have to have administrator rights or else, we have nothing to talk about).

Now, we have to deal with changing folder’s permissions:

  1. Again, right-click the folder, go to the Security tab and again click the Advanced button at the bottom.
  2. On the Permissions click the Change Permissions button.
  3. Uncheck Include inheritable permissions from this object's parent checkbox and click Add.
  4. Check Replace all child object permissions with inheritable permissions from this object.
  5. Select YOURACCOUNTNAME (YOURCOMPUTERNAMEYOURACCOUNTNAME) on list above and click Edit below it.
  6. Select second option (This folder, subfolders and files) on combobox below.
  7. Check first checkbox on the list below (Full control). This should mark all other checkboxes on that list.
  8. Make sure that the only checkbox below the list is not checked.
  9. Click OK four times, to close all open windows. After first click you’ll be prompted for confirmation. Click Yes.

After this mindless, stupid and very irritating process you should finally be able to delete this damn folder.

To conclude, let me tell you, that if above fail and you’ll still not be able to delete this folder, you have to options to consider:

  1. Repeat all above steps for all subfolders included in root folder (the one you want to delete).
  2. Repeat all above steps, but this time change owner and all permissions not for your own account, but for the entire group of administrators (i.e. Administrator (YOURCOMPUTERNAMEAdministrator)).

The visual way and some alternatives

mydigitallife.info have come with a fabulous guide on taking ownership of file or folder with many alternatives. Key article is above procedure, but this time heavily pictured. You’ll also find a command-line alternative mentioned in the beginning of this article as good as two others: for taking ownership by running a special prepared VBS script and by adding “Take Ownership” item to each file and folder context menu. Have fun.

Leave a Reply