Windows – How to get permissions to delete files on Windows 7

permissionswindows 7

I updated my laptop's OS from Windows XP to Windows 7. There are some leftover files from Windows XP on the computer now. If I try deleting them I get the following error:

You need permission to perform this action.

You require permission from S-1-…. to make changes to this folder.

What's weird is that I am logged in with the only user account on this machine and I have administrator privileges. I tried turning UAC off, but I still can't delete the files.

How can I force removal of these files?

Best Answer

It's possible that by upgrading, the old XP user was not converted well to Windows 7 - therefore these files are owned by a phantom user. You can follow the steps below:

  1. Take ownership of the files. Start a Command Prompt (cmd) as an administrator, and enter:

    takeown /f file
    takeown /f directory /r
    
  2. Give yourself full rights on the file:

    cacls file /G username:F
    cacls directory /T /G username:F
    

cacls can be used with wildcards and directory traversal. See also:
Security from the command line with CACLS
CACLS command

For a more evolved Visual Basic script see: Xcacls.vbs to modify NTFS permissions.