﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-c++点滴-随笔分类-Window系统</title><link>http://www.cppblog.com/itelite/category/20910.html</link><description>做生活的有心人</description><language>zh-cn</language><lastBuildDate>Mon, 07 Jul 2014 18:26:43 GMT</lastBuildDate><pubDate>Mon, 07 Jul 2014 18:26:43 GMT</pubDate><ttl>60</ttl><item><title>How to delete contents of Windows.Old folder easily using a script ?</title><link>http://www.cppblog.com/itelite/archive/2014/07/07/207559.html</link><dc:creator>huoxudong125</dc:creator><author>huoxudong125</author><pubDate>Mon, 07 Jul 2014 09:46:00 GMT</pubDate><guid>http://www.cppblog.com/itelite/archive/2014/07/07/207559.html</guid><wfw:comment>http://www.cppblog.com/itelite/comments/207559.html</wfw:comment><comments>http://www.cppblog.com/itelite/archive/2014/07/07/207559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/itelite/comments/commentRss/207559.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/itelite/services/trackbacks/207559.html</trackback:ping><description><![CDATA[<p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">Consider this scenario:</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">You re-install or upgrade&nbsp;Vista&nbsp;/ Windows 2008 / Windows 7&nbsp;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.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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:</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">REM JK-Windows.Old Deleter Version 1.0.181109 by jkadeesh</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">@echo off</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">setlocal</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">Title Windows.Old Deleter</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">set BAT_HOME=%~dp0<br />set BAT_NAME=%~s0<br />set BATFILE=%~nx0<br />set DRVLET=%~d0</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />if "%1"=="" goto interactive</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">REM Flash related lines are meant for deleting Flash specific .OCX files which cannot be easily deleted</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">if exist %1\Windows\System32\Macromed\Flash CD /D %1\Windows\System32\Macromed\Flash &amp;&amp; cacls *.* /P Everyone:F</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cd /d %DRVLET%</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">takeown /f %1 /R /d y<br />icacls %1 /grant administrators:F /t<br />rd /s /q %1</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">goto end</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />:interactive</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cls</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cd /d %DRVLET%\</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">IF EXIST %DRVLET%\Windows.old ECHO. &amp;&amp; ECHO Found %DRVLET%\Windows.old &amp;&amp; GOTO Auto</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">IF NOT EXIST %DRVLET%\Windows.old ECHO. &amp;&amp; ECHO NOT FOUND %DRVLET%\Windows.old &amp;&amp; ECHO.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />echo Enter folder name [with complete path] which needs to be deleted:<br />echo.<br />echo To exit type "x" and press Enter key</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">echo.<br />echo.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">set /p user=Folder Name[with path]:</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">if "%user%"=="x" goto end</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />if exist %user%\Windows\System32\Macromed\Flash CD /D %user%\Windows\System32\Macromed\Flash &amp;&amp; cacls *.* /P Everyone:F</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cd /d %DRVLET%\</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">takeown /f %user% /R /d y<br />icacls %user% /grant administrators:F /t<br />rd /s /q %user%</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />if not "%user%"=="x" goto interactive</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">goto end</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />:Auto<br />cls<br />ECHO.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cd /d %DRVLET%\</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">set user=Windows.old</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">if exist %DRVLET%\%user%\Windows\System32\Macromed\Flash CD /D %DRVLET%\%user%\Windows\System32\Macromed\Flash &amp;&amp; cacls *.* /P Everyone:F</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">cd /d %DRVLET%\</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">takeown /f %user% /R /d y<br />icacls %user% /grant administrators:F /t<br />rd /s /q %user%</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;"><br />goto end</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">:end<br />ECHO.<br />ECHO Exiting...<br />ECHO.<br />pause</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">How to use the above code?</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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,&nbsp;go to Control Panel &gt; User Accounts &gt; Turn User Account Control on or off ; then uncheck the option&nbsp;"Use User Account Control (UAC) to help protect your computer" and click OK. Then restart the computer.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">1. Copy/paste the code to Notepad</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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]</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">Note that the&nbsp;<strong>'Save as type'</strong>&nbsp;should be selected as "All Files (*.*)" before you click the Save button.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">3. Go to Command prompt</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">4. Type&nbsp;<strong>CD \&nbsp;&nbsp;</strong>to go to C:\</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">5. Type&nbsp;<strong>DeleteFiles&nbsp;<em>foldername</em></strong><em>&nbsp;</em>and then press Enter key</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">By default, the folder name is&nbsp;<strong>C:\Windows.old</strong>.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">If the Windows.old folder resides in D:\ [or a different drive], then enter the drive letter accordingly along with the folder name.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">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.</p><p style="color: #2a2a2a; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18.165599822998047px; background-color: #ffffff;">This posting is provided "AS IS" with no warranties. Use of included tools and reports are subject to the terms specified at&nbsp;<br /><a href="http://www.microsoft.com/info/cpyright.htm" mce_href="http://www.microsoft.com/info/cpyright.htm" style="color: #00749e; cursor: pointer; text-decoration: none; outline: none;">http://www.microsoft.com/info/cpyright.htm</a></p><img src ="http://www.cppblog.com/itelite/aggbug/207559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/itelite/" target="_blank">huoxudong125</a> 2014-07-07 17:46 <a href="http://www.cppblog.com/itelite/archive/2014/07/07/207559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>