topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 11:53 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Script to remove windows.old folder  (Read 6623 times)

glasskuter

  • Supporting Member
  • Joined in 2015
  • **
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Script to remove windows.old folder
« on: August 26, 2015, 01:06 PM »
Hello again guys,
I offer a community service to assist a lot of people remotely so don't always have hands on systems I deal with. There is a problem when it comes to deleting the Windows.old folder after one has upgraded to Windows 10. I have found that using disk cleanup works to remove this folder completely if the system is BIOS based.  However, if the upgraded system is UEFI based, the windows.old folder will not completely remove.  It leaves two folders relating to driverstore. Using elevated command will not remove the folder either as it responds with "access denied". I have tried changing privileges on the folder which also doesn't work. The only way I have found to completely get rid of the remaining 2 folders within windows.old is to use the command line at boot which I can't do remotely.

I found a script on the net which is quite old and not being familiar with code I am somewhat confused by it and what I am supposed to enter into the script.  The person who wrote the script is not as proficient as you guys when it comes to simplifying instructions for script dummies like me. Would you take a look at the attached script and clarify if it is valid and if it will work to achieve my goal of completely getting rid of the windows.old folder.
Assume in your response that the path to the windows.old folder is c:\windows.old.
Thanks for your superior work.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,964
    • View Profile
    • Donate to Member
Re: Script to remove windows.old folder
« Reply #1 on: August 26, 2015, 02:14 PM »
just making the script more accessible
(I'm not sure though if that's the right type of formatting)

Code: ActionScript [Select]
  1. REM JK-Windows.Old Deleter Version 1.0.181109 by jkadeesh
  2. @echo off
  3. setlocal
  4. Title Windows.Old Deleter
  5. set BAT_HOME=%~dp0
  6. set BAT_NAME=%~s0
  7. set BATFILE=%~nx0
  8. set DRVLET=%~d0
  9.  
  10. if "%1"=="" goto interactive
  11. REM Flash related lines are meant for deleting Flash specific .OCX files which cannot be easily deleted
  12. if exist %1\Windows\System32\Macromed\Flash CD /D %1\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
  13. cd /d %DRVLET%
  14. takeown /f %1 /R /d y
  15. icacls %1 /grant administrators:F /t
  16. rd /s /q %1
  17. goto end
  18.  
  19. :interactive
  20. cls
  21. cd /d %DRVLET%\
  22. IF EXIST %DRVLET%\Windows.old ECHO. && ECHO Found %DRVLET%\Windows.old && GOTO Auto
  23. IF NOT EXIST %DRVLET%\Windows.old ECHO. && ECHO NOT FOUND %DRVLET%\Windows.old && ECHO.
  24.  
  25. echo Enter folder name [with complete path] which needs to be deleted:   do i enter \c: \windows.old here in script??
  26. echo.
  27. echo To exit type "x" and press Enter key
  28. echo.
  29. echo.
  30. set /p user=Folder Name[with path]: I’m confused about what to enter here
  31. if "%user%"=="x" goto end
  32.  
  33. if exist %user%\Windows\System32\Macromed\Flash CD /D %user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
  34. cd /d %DRVLET%\
  35. takeown /f %user% /R /d y
  36. icacls %user% /grant administrators:F /t
  37. rd /s /q %user%
  38.  
  39. if not "%user%"=="x" goto interactive
  40. goto end
  41.  
  42. :Auto
  43. cls
  44. ECHO.
  45. cd /d %DRVLET%\
  46. set user=Windows.old
  47. if exist %DRVLET%\%user%\Windows\System32\Macromed\Flash CD /D %DRVLET%\%user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
  48. cd /d %DRVLET%\
  49. takeown /f %user% /R /d y
  50. icacls %user% /grant administrators:F /t
  51. rd /s /q %user%
  52.  
  53. goto end
  54. :end
  55. ECHO.
  56. ECHO Exiting...
  57. ECHO.
  58. pause

How to use the above code?
0. Disable User Access control [temporarily] - Once this task of deleting files / folders is completed,
you may want to re-enable User Access Control. To disable UAC,
go to Control Panel > User Accounts > Turn User Account Control on or off ; then uncheck the
option "Use User Account Control (UAC) to help protect your computer" and click OK. Then restart the computer.
1. Copy/paste the code to Notepad
2. Save the file with the file name as: DeleteFiles.bat to C:\ drive [any location is ok - you need
to go to the relevant location using the command line in step: 4]
Note that the 'Save as type' should be selected as "All Files (*.*)" before you click the Save button.
3. Go to Command prompt
4. Type CD \  to go to C:\
5. Type DeleteFiles foldername and then press Enter key
By default, the folder name is C:\Windows.old.
If the Windows.old folder resides in D:\ [or a different drive], then enter the drive letter accordingly
along with the folder name.
6. Then you will notice a lot of operation in the command window and the script will end with
"Exiting..." . Press any key to exit the script.
Then you will find Windows.old folder is completely removed - Note that with this method the
contents of Windows.old folder will not won't be sent to the Recycle bin.
DeleteFiles.bat can be run without supplying the folder name also - in that scenario, it will
consider Windows.old folder present in the current drive from which you run the batch file
Tom