Windows – Delete old windows / program files from second drive

ntfspermissionswindows 7

My PC has a bunch of extra drives. Most of them contain old copies of Windows and Program Files. My PC is called "PC", and my admin user is called "Tim". I've assigned ownership of these second drives to the user "PC\Tim", and also given the user "PC\Tim" full control on the drives. I then try to delete either the Windows or Program Files folders on these drives, and get the message.

"You require permission from PC\Tim to make changes to this folder."

The current owner of these folders is listed as "Tim (PC\Tim)". The effective permissions for these folders lists this user has every right.

The absurd "answers" on the microsoft community of course offer things like "Use Disk Cleanup" (which is a blatantly uneducated answer) or "just reformat the drive" (formatting avoids the problem rather than addressing it).

What are the correct steps to delete these old files?

Best Answer

  1. Open a Command Prompt with administrative privileges.
  2. Run following commands, one at a time (change "Z:\Program Files" with folder you want to delete):

    takeown /F "Z:\Program Files" /A /R /D Y
    icacls "Z:\Program Files" /T /grant administrators:F
    rd /s /q "Z:\Program Files"
    

Note 1 - OS Language: takeown ... /D Y The input Y stands for 'Yes' and will be different depending on OS Language. Program Files folder may also be named differently.

Note 2 - Older versions of Windows: If icacls and rd are not supported then try use cacls and rmdir instead

Explanation and documentation:

The issue might be that you do not have the correct permissions in the discretionary access control lists (DACLs) for the folder and its content. DACLs identifies the trustees that are allowed or denied access to a securable object. So simply giving the ownership to the folder might not be enough, but you also needs to grant permission in the DACLs. You can grant permission using the icacls command as shown as example above. Access Control Lists and DACLs explained

takeown takeown documentation Administrator recovers access to a directories and it's content that previously was denied, by making the administrators group the owner. /F [directory] specifies which directory, /A gives ownership to administrators group, /R performs it as recursive operation on directory, all files and sub-directories, /D suppresses confirmation prompts when user does not have "List Folder" permission with following Y option which take ownership of the directory. (Note: The Y option may be different depending on OS language).

icacls icacls documentation Grants the administrators group full access DAC permissions to directory. [directory] specify which directory, /T performs the operation on all specified files in directory and sub-directories, /grant grants specified user access rights with :F which gives full access. (Note: The group name administrators may be different depending on OS language)

rd rd documentation Deletes the directory with all its sub-directories and files. /s deletes the specified directory and its sub-directories including all files, /q specifies quiet mode so you get no prompt for confirmation, [directory] specify which directory to delete.

Related Question