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 :
- 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
- 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
Make your changes
Change ownership back.
icacls c:\Windows\Web /setowner "NT SERVICE\TrustedInstaller" /t
- 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
.
- Save current ACLs to a file somewhere.
icacls C:\Windows\Web /save "C:\Web.acl" /t
- Take ownership
takeown /f C:\Windows\Web /r
- Grant yourself full control.
icacls C:\Windows\Web /grant "%USERDOMAIN%\%USERNAME%":(F) /t
Make your changes
Change ownership back.
icacls c:\Windows\Web /setowner "NT SERVICE\TrustedInstaller" /t
- 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
notC:\Windows\Web
.
icacls C:\Windows /restore "C:\Web.acl"