posts - 10, comments - 0, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Consider this scenario:

You re-install or upgrade Vista / Windows 2008 / Windows 7 in a system. That may result the creation of "Windows.old" folder. You may try to delete that folder and its contents ; that may not work as expected - you may get multiple access denials and the folder "Windows.old" cannot be removed. This issue may be seen even if you have administrator privileges to the box.

For such a scenario, you may create a batch file based on the code below and run that batch file to delete the "Windows.old" folder:

REM JK-Windows.Old Deleter Version 1.0.181109 by jkadeesh

@echo off


Title Windows.Old Deleter

set BAT_HOME=%~dp0
set BAT_NAME=%~s0
set BATFILE=%~nx0
set DRVLET=%~d0

if "%1"=="" goto interactive

REM Flash related lines are meant for deleting Flash specific .OCX files which cannot be easily deleted

if exist %1\Windows\System32\Macromed\Flash CD /D %1\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F

cd /d %DRVLET%

takeown /f %1 /R /d y
icacls %1 /grant administrators:F /t
rd /s /q %1

goto end



cd /d %DRVLET%\

IF EXIST %DRVLET%\Windows.old ECHO. && ECHO Found %DRVLET%\Windows.old && GOTO Auto


echo Enter folder name [with complete path] which needs to be deleted:
echo To exit type "x" and press Enter key


set /p user=Folder Name[with path]:

if "%user%"=="x" goto end

if exist %user%\Windows\System32\Macromed\Flash CD /D %user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F

cd /d %DRVLET%\

takeown /f %user% /R /d y
icacls %user% /grant administrators:F /t
rd /s /q %user%

if not "%user%"=="x" goto interactive

goto end


cd /d %DRVLET%\

set user=Windows.old

if exist %DRVLET%\%user%\Windows\System32\Macromed\Flash CD /D %DRVLET%\%user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F

cd /d %DRVLET%\

takeown /f %user% /R /d y
icacls %user% /grant administrators:F /t
rd /s /q %user%

goto end

ECHO Exiting...

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.

This posting is provided "AS IS" with no warranties. Use of included tools and reports are subject to the terms specified at 

【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理