Automated cleanup of Temporary files, Internet files, downloaded files, recycle bin.
Syntax CLEANMGR [/d driveletter] option CLEANMGR [/d driveletter] /sageset:n option CLEANMGR [/d driveletter] /sagerun:n option Options /D driveletter The drive that you want Disk Cleanup to clean. NOTE: The /d option is not utilized with /SAGERUN:n. Specify the %systemroot% drive to see all the available options. /SAGESET:n Display the Disk Cleanup Settings dialog box and create a registry key to store the settings you select. REQUIRES ELEVATION The n value is stored in the registry and allows you to specify different tasks for Disk Cleanup to run. n can be any integer from 0 to 9999. /SAGERUN:n Run task 'n' All drives in the computer will be enumerated, and the selected profile will be run against each drive. /TUNEUP:n Run /sageset and /sagerun for the same n /LOWDISK Disk Cleanup will open with all options checked. Normally invoked when Windows notifies that of disk space is running out. /VERYLOWDISK Disk Cleanup will open with all options checked, no user prompts. /SETUP Analyze the system files left over from a previous Windows version. [Undocumented] /Autoclean Analyze the system files left over from a previous Windows version/in-place upgrade. and also remove those files automatically. [Undocumented] /HELP Display help /USAGE Display help /? Display help
If CLEANMGR is run without /sageset or /sagerun, it will start by calculating how much disk space could be saved. This makes the process slower to startup. By default only the Downloaded Program Files and Temporary Internet Files will be selected.
Some cleanup options require elevation, when run without elevation the GUI will include an option [Clean up System Files] which will relaunch CLEANMGR in Elevated mode. When necessary CLEANMGR can take ownership of the files before deleting them.
To enable Cleanmgr on older servers of Windows Server, open Server Manager and choose Add feature, then select "Desktop Experience"
After running cleanmgr on a server you may want to disable "Desktop Experience" again.
The following options can be toggled on or off when running /SAGESET:n
Catalog Files for the Content Indexer
Compress Old Files
Delivery Optimization Files
Diagnostic data viewer database files
DirectX Shader cache
Downloads (Personal downloads folder)
Downloaded Program Files *
Language resources Files
Old Chkdsk Files
Recycle Bin * (empties the recycle bin to recover the disc space)
Retail Demo Offline Content
Setup Log files
System Error memory dump files
System Error minidump files
Temporary Internet Files *
Temporary Setup Files
Temporary Offline Files
Update package Backup Files
User file history
Windows Defender Antivirus
Windows error reports and feedback diagnostics
Windows Update Cleanup
Windows Upgrade log files
Items marked with * have a [View Files] option in the GUI to view the individual files.
The Recycle Bin and Catalog Files for the Content Indexer may appear for more than one drive.
The user's 'Application Data' folder is not available for cleanup in the above list. Many files in Application Data hold system data that should not be deleted. However if you have an application that leaves a significant number of temporary/junk files in App Data, these can be selectively removed from a roaming profile with a VBScript like this.
The 'User Profile/Recent Items' folder can contain many more shortcuts than are useful. A very large number of these can affect logon/logoff times. To clear out the shortcuts:
Echo y| del *.*
Save the following batch script:
Taskkill /f /im Explorer.exe
Then to restart Windows Explorer, just run the batch file.
Registry settings for CLEANMGR are held in:
Here are a set of registry entries to turn on a typical selection of cleanmgr options, these can be used with REG or Regedit to pre-populate the regisitry as a scriptable alternative to running /SAGESET
Log files for CLEANMGR are stored in:
Choose a set of options for cleanup (this will display the GUI) and Save as settings group #64:
Run the saved settings group #64
To run Disk Cleanup this way regularly, you can create a shortcut which can be run from the Windows Startup folder or via a regular schedule. To run the saved settings group #64
%systemroot%\system32\cmd.exe /c CLEANMGR /sagerun:64
”Mrs. Joe was a very clean housekeeper, but had an exquisite art of making her cleanliness more uncomfortable and unacceptable than dirt itself“ ~ Charles Dickens
DELPROF - Delete user profiles and/or User Profile cache.
DEFRAG - Defragment hard drive.
Q253597 - Automating Disk Cleanup in Windows.
Equivalent bash command (Linux):watch - Execute/display a program periodically.