icacls problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

icacls problem

#1 Post by balubeto » 21 Jan 2016 03:15

Hi

I have Windows 10 v1511 Enterprise 64 bit.

I noticed that the icacls "<Home_directory_path>" /inheritance:e /T /L command, applied to the home directory of a directory structure, is run only the first level of the structure. Why?

How do I run it automatically in all the levels below?

Thanks

Bye
Last edited by balubeto on 22 Jan 2016 09:44, edited 1 time in total.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: icacls problem

#2 Post by Matt Williamson » 21 Jan 2016 09:41

I'd throw in a /C and see if you are getting errors.

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#3 Post by balubeto » 21 Jan 2016 12:36

Matt Williamson wrote:I'd throw in a /C and see if you are getting errors.


I tried but I get the "access denied" error. Why?

Thanks

Bye

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: icacls problem

#4 Post by Squashman » 21 Jan 2016 12:56

balubeto wrote:
Matt Williamson wrote:I'd throw in a /C and see if you are getting errors.


I tried but I get the "access denied" error. Why?

Thanks

Bye

Are you running the cmd prompt or batch file as Administrator by right clicking on it first and choosing Run as administrator?

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#5 Post by balubeto » 22 Jan 2016 04:47

Squashman wrote:
balubeto wrote:
Matt Williamson wrote:I'd throw in a /C and see if you are getting errors.


I tried but I get the "access denied" error. Why?

Thanks

Bye

Are you running the cmd prompt or batch file as Administrator by right clicking on it first and choosing Run as administrator?


I open the command prompt run as administrator and write the icacls "<Home_directory_path>" /inheritance:e /Q /T /C /L command.

I also noticed that if I write the icacls "<Home_directory_path>" /reset /Q /T /C /L command, it goes in a loop. Why? What should I write in order to avoid this?

Thanks

Bye
Last edited by balubeto on 22 Jan 2016 09:59, edited 2 times in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: icacls problem

#6 Post by Squashman » 22 Jan 2016 07:28

balubeto wrote:I open the command prompt run as administrator and write the icacls "Home_directory" /inheritance:e /Q /T /C /L command.

You sure about that. When you run cmd.exe as administrator it defaults the working directory to C:\windows\system32>.
So based on your information, you have a folder named Home_Directory located in C:\windows\system32>.

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#7 Post by balubeto » 22 Jan 2016 09:57

Squashman wrote:
balubeto wrote:I open the command prompt run as administrator and write the icacls "Home_directory" /inheritance:e /Q /T /C /L command.

You sure about that. When you run cmd.exe as administrator it defaults the working directory to C:\windows\system32>.
So based on your information, you have a folder named Home_Directory located in C:\windows\system32>.


I corrected the previous posts as I had mistyped.

Thanks

Bye

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#8 Post by balubeto » 22 Jan 2016 11:31

Apparently, the commands

Code: Select all

takeown /F "<Home_directory_path>" /A /R /D S /SKIPSL

icacls "<Home_directory_path>" /reset

icacls "<Home_directory_path>" /reset /Q /C /T /L

pushd "<Home_directory_path>" && ( rd /S /Q "<Home_directory_path>" 2>nul & popd )


reach my goal but the third command goes in loop and, to stop it, I have to press Ctrl+C. Why?

How do I do that the third command does not go in loop?

Thanks

Bye

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#9 Post by balubeto » 24 Jan 2016 05:47

For now, the only solution that I found is

Code: Select all

 takeown /F "<Directory_Path>" /A /R /D S /SKIPSL >nul 2>&1
 icacls "<Directory_Path>" /reset
 icacls "<Directory_Path>" /reset /Q /C /T /L >nul 2>&1
 pushd "<Directory_Path>" && ( rd /S /Q "<Directory_Path>" 2>nul & popd )
 


but I am sure that there is another better but I can not find it.

Someone would be able to find it?

Thanks

Bye

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#10 Post by balubeto » 24 Jan 2016 13:09

I hope that someone might find a solution better than mine because my solution is too slow because the third command does not stop to analyze my directory structure but the entire contents of the hard disk. Why?

Out of curiosity, what are the SIDs of the TrustedInstaller or Authenticated Users or System users so that I can try to remove them with the /remove:g option of the icacls command?

Thanks

Bye

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: icacls problem

#11 Post by balubeto » 26 Jan 2016 12:52

I think I found the best solution to remove a directory structure which also contains symbolic links and with ACLs managed by TrustedInstaller or Authenticated Users or System users:

Code: Select all

takeown /F "<Directory_path>" /A /R /D Y /SKIPSL >nul 2>&1

icacls "<Directory_path>" /reset

icacls "<Directory_path>" /grant:r Administrators:(OI)(CI)F /inheritance:e /Q /C /T /L >nul 2>&1

pushd "<Directory_path>" && ( rd /S /Q "<Directory_path>" 2>nul & popd )


Many thanks to all

Bye

Post Reply