Learning About Computers and the Internet
Tips Blog WinXP Internet Computing Downloads Vista/7 Home

Disk Cleanup Tool in Windows XP
The Windows operating system tends to build up temporary files over time. Managing these files with the system tool Disk Cleanup is discussed.

Regular Windows system maintenance should include the removal of unnecessary temporary files that the system accumulates. This computer housekeeping task is discussed in general on another page but here I will detail how to use the tool called Disk Cleanup that is included with the Windows operating system.

Although it has some limitations discussed in another section below, Disk Cleanup may be sufficient for many home PC users to help keep their system clean. The tool can be accessed in several ways .Disk cleanup toolIt is listed in the Start-All Programs- Accessories-System Tools group. It can also be opened by right-clicking on a drive icon in My Computer, choosing "Properties" from the context menu, and clicking the button "Disk Cleanup" on the properties sheet. Perhaps the quickest way to open the accessory is to enter "cleanmgr.exe" into the Start-Run line. (Actually, just entering "cleanmgr' is normally sufficient.) If you have more than one disk volume or hard drive, you will be asked to select the volume that should be cleaned. The figure on the right shows the main interface. Various different folders which store temporary files are listed. Certain listings are standard for all systems while others may vary according to an individual setup. The standard list includes Downloaded Program Files,Temporary Internet Files, the Recycle Bin, and Temporary files. The item "Downloaded Program Files" has a name that confuses many PC users. It does not refer to downloaded software programs but is a folder that contains ActiveX and Java applets that are sometimes downloaded for temporary use by Internet sites.

The entries of primary interest to the average home PC user are Temporary Internet Files, the Recycle Bin, and Temporary files. All can be cleaned by other routes but it is convenient to have them collected in one interface. The "Temporary files" listing refers to the Temp folder defined by the environment variable %TEMP% and does not necessarily provide for cleaning all Temp folders. Usually it will refer to the folder \Documents and Settings\{User}\Local Settings\Temp. In addition, a system may have other Temp folders such as \Windows\Temp. These are not cleaned in the default setup.

Scripting Disk Cleanup

More experienced PC users may be interested in the scripting possibilities that are possible when Disk Cleanup is invoked directly with the command "cleanmgr.exe". There are some switches that can be used as shown in the table below.

Switch options for cleanmgr.exe
Switch Function
/d driveletter Specifies a specific drive that you want Disk Cleanup to clean. Not used with /sagerun: n.
/sageset: n Displays the Disk Cleanup Settings dialog box and also creates a registry key to store the settings that you select. The integer "n" is an arbitrary number between 0 and 65535 that acts as a label or index for the particular settings chosen.
/sagerun: n Runs the specified tasks that were previously assigned to the n value by the \sageset option. All drives on the computer are cleaned.

Here are some possible ways to use the switches. To clean a specific drive F:, enter into Start-Run or a command prompt the command: cleanmgr.exe /D F:This will open the Disk Cleanup interface with the F: drive selected.

To create a Registry key with specific settings to be used in a subsequent operation of Disk Cleanup enter: cleanmgr.exe /sageset:100(Here the integer 100 is arbitrary. Choose any number from 0 to 65535.) The Disk Cleanup interface will open. Choose the cleanup options that you want associated with the index 100 and click OK. When you want Disk Cleanup to run the options you have chosen, enter:cleanmgr.exe /sagerun:100The options previously set up will then be run for all disks.

These commands can be used in scripts for manual or automated use. For some additional discussion see this Microsoft reference

Automating Disk Cleanup

Once options have been set up by creating one or more Registry keys, the Disk Cleanup utility can be scheduled to run at regular times. Many PC users may find that an automated procedure is a relatively painless way to do some housekeeping chores. Automation using Task Scheduler is described at this reference from Ramesh Srinivasan.

Limitations of Disk Cleanup

Systems with the file system NTFS often experience a long delay during disk cleanup because the default behavior is for Windows to check to see if it should apply file compression to old files. Systems may even stop responding. The solution is to edit the Registry as described in this Microsoft article. Open Regedit and delete this key:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Compress old filesIf you prefer, a REG file to carry this out can be downloaded here. If you are experienced at Registry editing, I think this is a Registry edit well worth considering. It can greatly speed up the use of Disk Cleanup. But first, back up the Registry.

Another quirk of Disk Cleanup is that it may leave a lot of temporary files untouched. It is designed to remove only files that are over a week old. Also, as mentioned above, it only cleans %TEMP% but other temp folders can be added as described in the next section. Also, a more thorough cleaning can be obtained by opening a Temp folder, selecting all files and sub-folders, and deleting. Note that any temporary files currently in use by the system will be locked and cannot be deleted. In fact, the presence of locked files will cause the process of deletion to stop. Additional methods of cleaning are discussed here.

Adding Features to Disk Cleanup

Other folders can be added to those that are cleaned up in the normal setup by doing a Registry edit. I think it is worthwhile to add the \Windows\Temp folder and I have posted a REG file that does this. It can be downloaded at this link.

Another change to be considered is to shorten the time from the default seven days that temp files are kept before they can be deleted. Again a Registry edit is required. To change the time files are kept in %TEMP%, go to the Registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files and change the Dword value "LastAccess" from "7" to a smaller number.

As always, do not edit the Registry unless you back it up first.

Disk cleanup in Windows 7 and 8

The general features of Disk Cleanup are similar in Windows 7 and 8 but some details are different. Using the tool in the newer operating systems is discussed on another page.

 << Home page ©2002-2016 Victor Laurie    Home page >>