The Windows Learning Center

How to Use the Disk Cleanup Tool in Windows Vista and 7

How to Keep Windows Vista and Windows 7 systems clean with the system tool Disk Cleanup is described.

Many of the basic factors involved in using the utility Disk Cleanup discussed on another page for Windows XP apply to Windows Vista and Windows 7 as well. However, some of the details of using the tool are different and they will be discussed 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
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
Calculating space saved by Disk Cleanup

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
Disk Cleanup in Windows 7

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
List of files to delete in Disk Cleanup

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
More options in Windows 7 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
cleanmgr switches

Only two of these switches are of interest here and they are described next.

Description of command line switches for Cleanmgr.exe

/Sageset:n
 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
cleanmgr /sageset:n
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
Disk Cleanup settings

Figure 8. Files to delete
File deletion options from dialog opened in command line

After you have created the Registry entry with your custom settings, another switch is used in a command to actually run the cleanup.

/Sagerun:n
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
cleanmgr /sagerun:n
can be used in scripts  and in Task Scheduler to schedule regular disk cleanups.