Delete old windows / program files from second drive?

Solution 1:

  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.

Solution 2:

What worked for me was a simplified version of this suggestion:

  1. Rename the Windows folder to Windows.old
  2. Run Disk Cleanup from the Start menu
  3. Select the drive containing the Windows.old folder
  4. Previous "Windows Installation(s)" then click on OK

Solution 3:

NOTE: Now that I think about it, you should be able to start from step 4, you just need to hit the "change permissions" button to get access. I'd test, but I'm out of directories to delete.

On Windows 10 (probably works with Windows 7 and 8 as well):

  1. Right-click on folder->properties->security->advanced.
  2. Click on Change next to owner (at the top). Enter your user name in the box, and hit check names. (Should convert into a MACHINENAME\USERNAME style.)
  3. Hit OK, OK, OK to get out of the security options.

You should now own the directory.

  1. Right-click on folder->properties->security->advanced. (Again.)
  2. Find "Users" in the permissions list. Click it, select edit, and choose full control.
  3. At the bottom, check "Replace all child permission entries...".
  4. Hit OK, then choose Yes in the warning box. Wait for the computer to apply the new permissions.

You should now have the permissions needed to delete the files. Do so. (Tested on both Program Files folders and Windows.old.)