Fixing files inaccessible due to broken NTFS-permissions

I have run into this problem a few times. Mostly on USB-drives that I then want to use on another system, or after reinstalling my Windows-machines and thereby changing the user ID's of the users.

Open a command-prompt with escalated ("Administrator") privileges:

  1. Press the Start-button.
  2. Type "cmd".
  3. Right-Click "Command Prompt" that shows up, and click "Run as Administrator" (or just hit CTRL+SHIFT+ENTER).

Now go to the problematic area, and use the following commands:

TAKEOWN /F [dir] /R /D Y
CD [dir]
ICACLS * /T /Q /C /RESET

Where [dir] is to be replaced with the path to the directory you're trying to fix. It will, in order of the above commands:

  1. Forcible make you own all files in that directory, recursively.
  2. Change in to the directory.
  3. Reset all Access Control Lists on every object in that directory to the system default.