Delete Windows System Folders From Former OS Drive

I demoted a former Windows OS drive to a data drive recently without formatting it. The SSD still contained my OneDrive folder, and I did not want to download it again or copy it from a backup. Therefore, all of the Windows system folders were still on the drive. I tried to delete them, but whatever I did using the GUI, Windows slapped my fingers. I was not able to remove the Program Files and Windows folder.

There is a solution using the command line, though. You must execute all commands in an Administrator command prompt.

Example for the Program Files directory.

takeown /f "Z:\Program Files" /a /r /d Y
icacls "Z:\Program Files" /t /grant administrators:F
rd /s /q "Z:\Program Files"

Gotcha: I have noticed that I had to execute the statements a second time on some folders to delete them finally.

An exception is the Windows directory. It cannot be removed using these commands. I have found another workaround that tricks Windows into believing it is a previous Windows installation. Rename the Windows directory to “Windows.old” and then run Disk Cleanup -> Clean up system files. Windows will detect this as an old installation and offer to remove it.

Documentation

  • takeown
    • /f – Path to folder
    • /a – Give ownership to Administrators group
    • /r – Recursive
    • /d Y – Do not require confirmation
  • icacls
    • /t – “Recursive”
    • /grant – Replace previous permission with new owner and full access (:F)
  • rd
    • /s – Recursive
    • /q – Quiet mode, do not require confirmation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.