I had problems with files with very long paths (greater than 256 characters). The two commands
takeown /f "C:\path\to\really_long_folder_name" /r
icacls "C:\path\to\really_long_folder_name" /reset /T
worked except for these files with really long paths and names. I ended up renaming
"C:\path\to\really_long_folder_name"
to
"C:\path\to\r"
and then running
takeown /f "C:\path\to\r" /r /D Y
icacls "C:\path\to\r" /grant Everyone:(F) /t /c /q
after which I could rename the folders to something more sensible. takeown's /D Y answers yes to prompts. For icacls I used /grant to give full access to everyone (as I was just trying to access data on a hard drive from a dead PC), with /t to process sub folders and files, /q to run in quiet mode (hide successes) and /c to show errors. I repeated the process, renaming folders until all the files permissions were updated successfully.
Hopefully this helps someone who has come across errors similar to the "failed to enumerate objects in the container access is denied" errors I was getting when trying to gain access to the data from an old hard drive.
3Excellent technical advice ... your solution was the only one that worked. Thanks again. – carrabino – 2014-08-24T21:11:18.197
4Best advice, need to use both takeown and icacls. – gnac – 2014-12-02T23:41:08.077
This will fix problems even if there is a deny permission set – bradvido – 2015-09-09T14:22:23.837
2/A option is useful if you wish to give 'ownership to the administrators group instead of the current owner'. You need to have Administrators privileges to do this. May need to open cmd window using ctrl-shift-enter. – PeterVermont – 2015-12-02T15:40:15.777
4I've added the
/D Y
parameter totakeown
so it auto-confirms recursed directories where you don't have 'list directory' permissions for. – Jeroen Wiert Pluimers – 2016-07-06T14:51:19.2733@JeroenWiertPluimers, although it's a good advice I've removed the edit as it's (stupidly enough) a localised parameter so on English Windows it will be
/D Y
, on French one/D O
, maybe on Spanish/D S
, etc. – laurent – 2017-04-18T09:44:57.787takeown fails with the filename, directory label or volume label syntax is incorrect and icacls aborts itself saying it would create an unusable ACL. Running on C: directly in an elevated command prompt Win 8.0 – person27 – 2019-10-26T20:08:46.710