Training
Module
Maintain disks and volumes - Training
This module explores file system fragmentation and the tools that you can use to reduce fragmentation. Students will learn how Windows can compress files to take up less space on the hard disk.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article describes how to run the Disk Cleanup tool (cleanmgr.exe) by using command-line switches. cleanmgr.exe is designed to clear unnecessary files from your computer's hard disk. You can configure cleanmgr.exe with command-line switches to clean up the files you want. You can then schedule the task to run at a specific time by using the Scheduled Tasks tool.
Applies to: Windows Server 2008 R2 Service Pack 1, Windows 7 Service Pack 1
Original KB number: 253597
You can start the Disk Cleanup tool by running cleanmgr.exe, or by selecting Start > Programs > Accessories > System Tools > Disk Cleanup. Disk Cleanup supports the following command-line switches:
/d <driveletter>
: - This switch selects the drive that you want Disk Cleanup to clean. The /d
switch isn't used with /sagerun:n
.
/sageset:n
- This switch displays the Disk Cleanup Settings dialog box and creates a registry key to store the settings you select. The n value is stored in the registry and allows you to specify different tasks for Disk Cleanup to run. The n value can be any integer value from 0 to 65535. To get all the available options when you use the /sageset
switch, you may need to specify the drive letter that contains the Windows installation.
For more information, see Registry key information.
/sagerun:n
- This switch runs the specified tasks that are assigned to the n value by using the /sageset
switch. All drives in the computer will be enumerated, and the selected profile will be run against each drive.
For example, in Scheduled Tasks, you could run the following command after running the cleanmgr /sageset:11
command:
cleanmgr /sagerun:11
.
This command runs Disk Cleanup with the options that were specified with the cleanmgr /sageset:11
command.
The available options for Disk Cleanup that you can specify by using the /sageset
and /sagerun
switches include:
If you select the drive that contains the Windows installation, all of these options are available on the Disk Cleanup tab. If you select any other drive, only the Recycle Bin and Catalog files for content index options are available on the Disk Cleanup tab.
The More Options tab contains options for cleaning up Windows components or installed programs. You can use the Windows Components option to create free space by removing optional Windows components that you don't use. Selecting the Clean Up button for this option starts the Windows Components Wizard. You can use the Installed Programs option to free more disk space by removing programs that you don't use. Selecting this Clean Up button starts the Change or Remove Programs option in the Add/Remove Programs tool.
After you run cleanmgr.exe with the /sageset:n
switch, some of the registry sub keys under the the following registry key are modified:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\
Each of the modified registry sub keys may contain a REG_DWORD type registry value StateFlagsNNNN, where NNNN is the number n specified in the switch. For example, after you run the cleanmgr /sageset:9
command, a registry value Stateflags0009 is added. The registry value can be set as one of the following values.
Note
Under the VolumeCaches registry key, the Offline Pages Files registry sub key doesn't have the stateflags values. There is not an option to delete these files.
For more information, see Creating a Disk Cleanup Handler.
For a Microsoft Windows XP version of this article, see How to Automate the Disk Cleanup Tool in Windows XP.
Note
Disk Cleanup option on drive's general properties and cleanmgr.exe is not present in Windows Server 2008 R2 by default. For more information on how to have Disk Cleanup button or cleanmgr.exe on Windows Server 2008 R2, see Disk Cleanup option on drive’s general properties and cleanmgr.exe is not present in Windows Server 2008 R2 by default.
Training
Module
Maintain disks and volumes - Training
This module explores file system fragmentation and the tools that you can use to reduce fragmentation. Students will learn how Windows can compress files to take up less space on the hard disk.