Understanding how to use Icals & Takeown to make changes and reset in Windows 10

You don't need to do directory and contents separately. Nor do you want to reset permissions.

Simple method

From an Administrator command prompt :

  1. Take ownership of directory and contents. You could narrow this to the specific item you want to alter depending how many there are.

takeown /f C:\Windows\Web /r

  1. Grant yourself full control. Note %USERDOMAIN%\%USERNAME% is automatically replaced with your user - you don't need to substitute anything here.

icacls C:\Windows\Web /grant "%USERDOMAIN%\%USERNAME%":(F) /t

  1. Make your changes

  2. Change ownership back.

icacls c:\Windows\Web /setowner "NT SERVICE\TrustedInstaller" /t

  1. Remove authority granted

icacls C:\Windows\Web /remove:g "%USERDOMAIN%\%USERNAME%":(F) /t

Alternative method

An alternative is to save and restore ACLs which would cover the situation where your user already had granted authority to some of the objects in the directory that you would not want to remove with /remove:g.

  1. Save current ACLs to a file somewhere.

icacls C:\Windows\Web /save "C:\Web.acl" /t

  1. Take ownership

takeown /f C:\Windows\Web /r

  1. Grant yourself full control.

icacls C:\Windows\Web /grant "%USERDOMAIN%\%USERNAME%":(F) /t

  1. Make your changes

  2. Change ownership back.

icacls c:\Windows\Web /setowner "NT SERVICE\TrustedInstaller" /t

  1. Restore ACLs from the file you created in step 1. Note that these are restored for the parent directory so in this case C:\Windows not C:\Windows\Web.

icacls C:\Windows /restore "C:\Web.acl"