18

I have found myself in a somewhat unique situation.

I have a folder. This folder, somehow, lost its owner.

In "Advanced Security Settings for FOLDER" under "Current owner:" is displayed:

Unable to display current owner.

I am trying to delete this folder with no success. I have tried taking ownership with both my user and the Administrator user and both yield

Unable to set new owner on FOLDER, Access is denied

I have tried to grant administrator full privileges via the Windows shell running as administrator:

icacls FOLDER /grant administrators:F

And I have tried to remove the folder via the Windows shell running as administrator:

rmdir FOLDER /s

which return:

Access is denied

Does anyone have any idea as to how I can delete this folder?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Gimli
  • 498
  • 1
  • 3
  • 14
  • If the folder in question is inside another empty one, or if this can be arranged, see http://superuser.com/a/423821/96662 – Harry Johnston Jul 18 '13 at 20:33
  • In my case I just copied pasted a file from this folder to another (all using explorer) and after that I was unable to delete the source. After going through all the options on net, I ended up closing all my explorer windows and then from command prompt was able to delete the folder (wasn't able to before closing all explorer windows). – Avnish Jan 20 '16 at 16:46

5 Answers5

26

If you tried to delete a file/folder and it failed due to a process holding on to it, it will lose it ownership. Use Process Explorer and do a search for the folder/file. It will show what process is using that folder/file. When you end the process, the folder/file will disappear.

Gerhard Powell
  • 5,965
  • 5
  • 48
  • 59
  • 6
    This worked well. For others, Process Explorer is a small utility distributed by Microsoft at https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer. `Ctrl+F` lets you "Find Handle or DLL'. I typed the file name there. – wibeasley Mar 05 '18 at 20:53
  • 3
    I think that's the main cause for those "lost ownership" cases. Unfortunately I can't vote more than once :) – Damien B Apr 26 '18 at 13:36
  • 1
    I have this same problem, but Process Explorer could not find which process was using the folder. My solution was to restart my pc. – Cardinal System Sep 03 '18 at 06:30
  • I have the same problem! I was able to find the "handles" that are locking my files, but they are under the System process. When I try to delete them, I get "error opening process: The handle is invalid" – Vin Shahrdar Feb 07 '20 at 15:46
  • @Cardinal-ReinstateMonica You can post that in an answer if you'd like. – Xbox One Aug 14 '20 at 21:16
9

Try chkdsk /F in cmd with admin privilege!

Because the folder may contain a file without owner, which is an error in your file system.

If that folder is in your boot disk (C:), cmd will ask you whether to scan when the next time you launch the computer, type "y" to confirm.

After the scan chkdsk will delete the damaged file(s).

I got this problem after uninstalled Android Studio, I can't delete C:\Program Files\Android\Android Studio. Tried DEL/RD/TAKEOWN/ICACLS... for one hour, none of them works for me. Then I realized, that folder contains some damaged files without owner... Guess it's a bug of Windows or Android Studio...

This is one of the possibility why some folders or files cannot be deleted even with admin privilege.

Hope this helps the questioner and people who have the same problem!

Kirk
  • 446
  • 4
  • 18
  • I had the same issue, I install Mcafee antivirus, then some exe files became corrupted. – pat Oct 27 '17 at 11:05
  • Had the same issue, and was due to Android Studio. `CHKDSK /F` then reboot. Got rid of the undeletable folder. – Madushan Dec 12 '17 at 05:53
4

I had this problem when I had a cygwin terminal in the locked directory. After changing directories in the cygwin window, I was able to remove the windows directory.

birkner
  • 133
  • 9
3

Download and add Take Ownership registry. Then right click on folder and press Take Ownership and choose your username.

vujke
  • 483
  • 7
  • 14
  • 1
    this a updated address of the link you've mentioned.http://www.howtogeek.com/howto/windows-vista/add-take-ownership-to-explorer-right-click-menu-in-vista/ – Faeze Aug 28 '14 at 11:40
2

The ownership of the folder shouldn't affect its deletability, as long as the parent folder's access rights include write access for the deleting user.

A folder doesn't really lose its owner, but its owner may cease to exist. However, the folder still has an owner ID, and for most intents and purposes, that is still valid.

@birkner is on the right track. Check to see if you have any processes running in that directory, and if so, terminate them.

Keith Tyler
  • 719
  • 4
  • 18
  • In this scenario even if the parent directory is owned by the current user the directory can still not be deleted on my machine. – Freya Jul 30 '17 at 13:25
  • 1
    That would lend itself to a stale process that had the directory open. – Keith Tyler Jul 31 '17 at 19:07
  • 1
    That would explain why I could delete the directory after a reboot. – Freya Aug 01 '17 at 11:51
  • 1
    Process Explorer can also be useful in these situations. https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer – Keith Tyler Aug 02 '17 at 17:39