How to Use the Disk Cleanup Tool in Windows Vista and 7
An important Windows maintenance task is regularly keeping the disk clean from accumulating unnecessary files and programs. An important system tool that helps with this housekeeping chore is the built-in Windows accessory called the Disk Cleanup tool and its use is described here.
How to open Disk Cleanup
The tool can be accessed in several ways. It is listed in the Start-All Programs- Accessories-System Tools group. It can also be opened by right-clicking on a drive icon in Computer, choosing "Properties" from the context menu, and clicking the button "Disk Cleanup" on the properties sheet, as shown below.
Figure 1. Disk properties
Another way to open the accessory is to enter "clean" into the Start-Search bar. If you have more than one disk volume or hard drive, you will be asked to select the volume that should be cleaned. Vista users will also be asked if they want to clean up just their own files or all of the files on the computer.
Figure 2. Calculating space saved
Whichever way you choose to access Disk Cleanup, Windows will first spend a minute calculating how much space you might save. You will see the box shown on the left.
How to use Disk Cleanup
The figure below shows the main interface for Disk Cleanup in Windows 7. 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.
Figure 3. Disk cleanup dialog
The next image shows the full contents of the scrollable window "Files to delete" from Figure 3 above.
Figure 4. List of files to delete
If the button "Clean up system files" is chosen, an additional tab "More Options" is added to the interface in Windows 7 as the figure below shows. This provides for some advanced options such as removing shadow copies. This tab is present in the Vista interface without the need to click a button if you make the choice to clean up all files on the system.
Figure 5. Additional options in Disk Cleanup
Using command line switches to customize and run Disk Cleanup
The executable file for Disk Cleanup is cleanmgr.exe and it can be run from a command prompt with elevated privileges. There are even some command-line switches that allow you to customize the actions of Disk Cleanup. This makes it possible to create shortcuts and scripts to run Disk Cleanup automatically. With the switches, several different ways of using Disk Cleanup can be set up
There are six switches as shown in the figure below. The figure shows a window that appears when the command "cleanmgr /?" is entered in a command prompt.
Figure 6. Command-line switches for Cleanmgr.exe
Only two of these switches are of interest here and they are described next.
Description of command line switches for Cleanmgr.exe
In this switch, "n" is a numeric label that can be any number from 0 through 65535. The number is arbitrary and provides a way to configure Cleanmgr to run with different settings. The number identifies a Registry entry that is created when the command is run. You can use different values of "n" to create quick ways to run Disk Cleanup for different tasks.
Running the command
as administrator opens a dialog box that allows you to select Disk Cleanup options. It is shown in Figure 7 below. This dialog is similar to that reached from the graphical user interface in Figure 3 but contains additional entries for "files to delete" as shown in Figure 8. Compare Figure 8 with Figure 4 to see the difference. After you choose which files are to be deleted and click "OK", a registry key that corresponds to the number you entered is saved with the file deletion settings for Disk Cleanup that you have selected.
Figure 7. Dialog for settings of Cleanmgr.exe
Figure 8. Files to delete
After you have created the Registry entry with your custom settings, another switch is used in a command to actually run the cleanup.
A command with this switch retrieves the saved settings from the Registry for the value of n that you have created and then runs Disk Cleanup without requiring any interaction on your part. If no Registry entry for "n" has been previously created, the default settings are run. The command
can be used in scripts and in Task Scheduler to schedule regular disk cleanups.