What's wrong with this script? Why can it not delete windows.old?


  1. Posts : 681
    Windows 10 x64 Pro
       #1

    What's wrong with this script? Why can it not delete windows.old?


    So i had used this script in the past (or so i thought?) to clean up some of windows leftovers, and it worked. Either my memory is off, or something changed. Either way - this time it did not.

    It took care of everything except windows.old. Access is denied and left it. Even tried to right click > take ownership and delete manually after the fact, and still got access is denied.

    Only way i was able to remove it was ala windows built in cleanup tool.

    Does this now require like System/TI privileges? Would I have to incorporate something that can elevate and run the script with that?

    Code:
    @echo off
    @echo This will remove windows version update leftovers.  Must be ran as admin.
    @echo --------------------------------
    @echo WARNING! This will prevent rolling back!
    @echo --------------------------------
    pause
    takeown /f %SystemDrive%\$SysReset\* /a /r /d y
    takeown /f %SystemDrive%\$Windows.~BT\* /a /r /d y
    takeown /f %SystemDrive%\$Windows.~WS\* /a /r /d y
    takeown /f %SystemDrive%\$WinREAgent\* /a /r /d y
    takeown /f %SystemDrive%\Windows.old\* /a /r /d y
    icacls %SystemDrive%\$SysReset\*.* /t /grant administrators:f
    icacls %SystemDrive%\$Windows.~BT\*.* /t /grant administrators:f
    icacls %SystemDrive%\$Windows.~WS\*.* /t /grant administrators:f
    icacls %SystemDrive%\$WinREAgent\*.* /t /grant administrators:f
    icacls %SystemDrive%\Windows.old\*.* /t /grant administrators:f
    rd /s /q %SystemDrive%\$SysReset
    rd /s /q %SystemDrive%\$Windows.~BT
    rd /s /q %SystemDrive%\$Windows.~WS
    rd /s /q %SystemDrive%\$WinREAgent
    rd /s /q %SystemDrive%\Windows.old
    @echo --------------------------------
    @echo $SysReset deleted.
    @echo $Windows.~BT deleted.
    @echo $Windows.~WS deleted.
    @echo $WinREAgent deleted.
    @echo Windows.old deleted.
    @echo --------------------------------
    pause
      My Computer

  2. Samuria's Avatar
    Posts : 6,051
    windows 10
       #2

    Its protected as system files you have to use disk clean to remove it or storage sense
      My Computer

  3. SIW2's Avatar
    Posts : 1,665
    trying to install win10
       #3

    You could use a permission bypass driver, or something like nsudo

    https://github.com/Thdub/NSudo_Insta...staller_AIO.7z

    NSudo_8.0_All_Components.zip - 蓝奏云
      My Computer

  4. TairikuOkami's Avatar
    Posts : 4,671
    Windows Home Dev 21xxx x64
       #4

    I can not remove windows.old after an upgrade, because Windows is still using one dll driver from it. I removed all folders manually, till I got to the file, that was causing it, only a few KB in size, so I let it go.
      My Computer


  5. Posts : 681
    Windows 10 x64 Pro
    Thread Starter
       #5

    would executing the script with nsudo suffice? Or would it need to be baked into the script?
      My Computer

  6. sygnus21's Avatar
    Posts : 5,376
    Win 10 Pro (x64) 20H2 (19042.928)
       #6

    TairikuOkami said:
    I can not remove windows.old after an upgrade, because Windows is still using one dll driver from it. I removed all folders manually, till I got to the file, that was causing it, only a few KB in size, so I let it go.
    Hmmm, that's odd. Option here has always worked for me without fail - Delete Windows.old Folder in Windows 10 and I've done plenty of upgrades.

    Anyway the system is supposed to automatically delete after 10 days unless of course there's an issue.
      My Computers

  7. spunk's Avatar
    Posts : 2,837
    Windows 10 Pro 64 Bit 20H2
       #7

    You can also go to Settings/Storage and delete Temporary files there to delete Windows.old Delete Windows.old Folder in Windows 10
      My Computer


  8. Posts : 681
    Windows 10 x64 Pro
    Thread Starter
       #8

    TairikuOkami said:
    I can not remove windows.old after an upgrade, because Windows is still using one dll driver from it. I removed all folders manually, till I got to the file, that was causing it, only a few KB in size, so I let it go.
    yea i sorta just found this out the hard way i think. I ran it, and it was blunted by access denied permissions.

    but some of what it got seems to have stopped some of my applications from starting as admin as they're designed to do which is causing all kinds of issues.

    I had always operated under the assumption that folder was there PURELY if you wanted to roll back. I didnt expect windows to intermingle things with it. Sigh
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 10:49.
Find Us




Windows 10 Forums