How do I get permissions to delete files on Windows 7?

64

34

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?

lajos

Posted 2009-10-26T06:47:19.160

Reputation: 893

Answers

85

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.

harrymc

Posted 2009-10-26T06:47:19.160

Reputation: 306 093

1@harrymc, Regarding "these files are owned by a phantom user" is that even possible? – Pacerier – 2015-04-25T11:02:55.850

2@Pacerier: Yes, I call "phantom" a user (not built-in) account created on one computer, and so does not exist on another one. – harrymc – 2015-04-25T11:56:58.217

1Few notes: 1. takeown outputs a lot of noise so you can stuck something like "> output" at the end of the command to make it go faster 2. Use /t cacls switch to make go recursively. Otherwise - great tips! – Evgeniy Dolzhenko – 2011-09-22T09:24:07.243

1The takeown command results in an error: C:>takeown /f olddir /r ERROR: The current logged on user does not have ownership privileges on the file (or folder) "C:\olddir". – lajos – 2009-10-26T13:15:42.197

6Did you launch the command prompt by right-click on cmd.exe and "Run as administrator"? – harrymc – 2009-10-26T14:12:00.067

1Thanks for pointing that out. I did not run as administrator. It's working now! – lajos – 2009-10-26T14:26:31.413

1I'd advise to only do that to personal files such as documents and pictures, or to files you're going to delete. I once did to the whole C:\ drive to see what happened and the system bit back - programs stopped working, the whole system became unstable. – Alex – 2013-04-04T08:24:41.177

11I still get "ERROR: Access is denied" even after running cmd as administrator! – B T – 2013-07-12T18:26:33.340

29

The command line arguments for taking ownership should be in this order

takeown /f <directory> /r
/f  filename or directory name pattern
/r  recurse

NOTE: cacls is now deprecated, please use icacls

icacls <directory> /grant <user>:f /t
 f  full access
/t  recurse

Lessan Vaezi

Posted 2009-10-26T06:47:19.160

Reputation: 403

6

In my case taking ownership was not enough in Windows 7 for my particular circumstances (my Windows 7 installation was made using Symantec Backup Exec from another machine and the folder was under source control).

I had to perform two further steps:

  1. Right click the folder containing the files you want to delete and select 'Properties' -> 'Security' -> 'Advanced' -> select your user -> 'Change permission' -> Check "Replace all child object permissions with inheritable permissions from this object"

  2. Delete the files in the folders manually from the innermost to the root. Delete the folders once they are empty, i.e. if you have "folder1->folder2" first you delete the contents of folder2, then delete folder2 etc.

If the other solutions are not enough, you can try these further steps.

Durden81

Posted 2009-10-26T06:47:19.160

Reputation: 199

1

That S-1-... is a GUID left over from the previous install. Obviously NEWSYSTEM\Administrator isn't part of the OLDSYSTEM\Administrators group.

You need to take ownership of the drive, let the changes propagate, then you should be able to delete the files.

tsilb

Posted 2009-10-26T06:47:19.160

Reputation: 2 492

1

Usually takeown and (i)cacls do the job.

Alternatively, you can use Unlocker to delete it (probably it will require reboot),
or use Sysinternals' PsExec to get SYSTEM user privileges and delete those files (this one will work on some files, may fail on others).

But if that folder has a lot of files, it will take a lot of time to takeown privileges (it took me about 20 minutes, depends on HDD speed). So in this case any LiveCD/DVD/USB is faster, as they don't require any privileges to delete the folder.

Jet

Posted 2009-10-26T06:47:19.160

Reputation: 2 232