From time to time you might find yourself having troubles with file permissions in a Windows environment. This issue will show itself in you not being able to edit, change, move or delete one or multiple files on your computer. This can happen if the ownership settings of the file(s) are corrupted which happen once in a while. To recover the file permissions we are going to use two tools native to Windows; takeown and cacls.
The way to recover the file permissions are to do the following:
Right-click the Start button and press Windows Powershell (Administrator)
Execute the command takeown /f <full path to file> e.g., takeown /f C:\Windows\WindowsUpdate.log
This will transfer ownership from whichever user- or system account to the account executing the command. However, ownership does not necessarily grant access to deleting the file.
To reset this permission set, execute the command cacls <full path to file> /G <Username>:F e.g., cacls C:\Windows\WindowsUpdate.log /G Morten:F
You have now effectively transferred ownership permissions to your account.
To read the full list of operators and parameters for the commands, please refer to the official Microsoft documentation for cacls and takeown.