CLEANMGR.exe

Automated cleanup of Temp files, Internet files, downloaded files, recycle bin.

Syntax
     CLEANMGR option

Options
       /d driveletter: Select the drive that you want Disk Cleanup to clean.

       /sageset:n      Display the Disk Cleanup Settings dialog box and create
                       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.
                       n can be any integer from 0 to 65535.
                       Specify the %systemroot% drive to see all the available options.

      /sagerun:n       Run task 'n'
                       All drives in the computer will be enumerated, and the
                       selected profile will be run against each drive. 

    Only one of the 3 options above can be run at a time

      /TUNEUP:n        Run sageset + sagerun for the same n

      /LOWDISK         Run with the default settings.

      /VERYLOWDISK     Run with the default settings, no user prompts.

      /SETUP           Undocumented
      /Help            Undocumented
      /Usage           Undocumented
      /?               Display help

To enable Cleanmgr on Windows 2008, open Server Manager and choose Add feature, then select "Desktop Experience"
After running cleanmgr on a server you will probably want to disable "Desktop Experience" again (or use this script.)
When necessary cleanmgr may take ownership of the files before deleting them.

Registry settings for CLEANMGR are held in:
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]

Examples

CLEANMGR /sageset:64

CLEANMGR /sagerun:64

Options that can be chosen for cleanup:

Temporary Internet Files
Temporary Setup Files
Downloaded Program Files
Old Chkdsk Files
Recycle Bin
Temporary Files
Temporary Offline Files
Offline Files
Compress Old Files
Catalog Files for the Content Indexer
System files: Debug/chkdsk/Installer/Memory dump/Windows update/error reporting logs.

Items in bold may appear in more than one drive i.e not just in %SystemRoot%

Application Data

Many files in Application Data hold system data that should not be deleted, however some applications do leave files which you may want to delete from a roaming profile, these can be selectively removed with a VBScript like this.

Recent files

The 'User Profile/Recent' folder (for Start, Documents) may contain many more shortcuts than are set to display in the GUI. A very large number of these can affect logon/logoff times.
To clear out the shortcuts:

cd %userprofile%\Recent
echo y| del *.*

Close Locked files by restarting Windows Explorer

Close all applications
Open a command prompt
Type:
taskkill /im explorer
This should kill explorer and bring up a logout/shutdown dialogue box.
Simultaneously press CTRL+SHIFT+ALT.
While you keep these keys pressed, click [Cancel] in the Shut Down Windows dialog box.
In the command prompt window, you should now be able to delete the locked files.
At the command prompt, type explorer, and press ENTER to restart Windows Explorer.

”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

Related:

DELPROF - Delete user profiles and/or User Profile cache
DEFRAG - Defragment hard drive (XP)
Q253597 - Automating Disk Cleanup in Windows
Q315246 - Automating Disk Cleanup in Windows XP
Q812248 - Disk Cleanup stops responding while compressing old files
Equivalent bash command (Linux): watch - Execute/display a program periodically


© Copyright SS64.com 1999-2014
Some rights reserved