Share via

cleanmgr command line switches

Anonymous
2009-07-09T17:05:16+00:00

When I run cleanmgr /? at the command prompt (as administrator) I get the following dialogue box...

USAGE

cleanmgr [/SAGESET:n | /SAGERUN:n | TUNEUP:n | /LOWDISK | /VERYLOWDISK | /SETUP]

I found microsoft documentation on the SAGESET and SAGERUN switches.

http://support.microsoft.com/default.aspx/kb/253597

What do the other switches do?

Thanks.

Windows for home | Previous Windows versions | Apps

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

18 answers

Sort by: Most helpful
  1. Anonymous
    2014-12-05T10:40:24+00:00

    Freeing up Disk Space

    Last Updated 18-1-2014

    Contents

    • To see how much space you have used and free
    • To see where files are taking up space
    • Disk Cleanup
    • System Restore
    • Repair the Recycle Bin
    • Repair Temporary Internet Files
    • Delete Files in the System and Service Profiles Temp Folder
    • Check Size of Swap File
    • Turn Off Hibernation
    • Compact the Various Databases Windows Uses
    • Remove files updated by Service Packs
    • Relocate Your Documents
    • Delete Backed Up Files Made By Photo Gallery
    • Extending The Size of the Drive
    • Compress Files
    • Turn off Low Disk Space Warnings
    • Supercharging Disk Cleanup

    To see how much space you have used and free

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    For the system drive

    wmic volume where (DriveLetter='%systemdrive%') get Caption, Capacity, freespace /format:list

    For all drives

    wmic volume get Caption, Capacity, freespace /format:table

    If you want to store this info on your desktop

    wmic /append:"%userprofile%\desktop\Free Disk Space Report.html" volume get Caption, Capacity, freespace /format:htable

    To open double click Free Disk Space Report.html on your desktop or type

    start "" "%userprofile%\desktop\Free Disk Space Report.html"

    Then come back here after cleaning and repeat these commands to see the difference.

    If for some reason the wmic command doesn't work use these two commands. Both take a long time.

    defrag %systemdrive% -a

    or

    dir %systemdrive%\.* /a /s*

    To see where files are taking up space

    This will list the number of files and size for folders on your drive. Each command does a subset so you can manage it better.

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    Then configure the command prompt. Right click the Command Prompt's titlebar - Properties - Layout tab - and enter 1000 for Screen Buffer Size Height and 43 (or 50) for Window Size Height. Change the Color (Color tab) and Font (Font tab) if you want.

    To see size of folders in Documents, excluding music, video, or pictures folders.

    for /f "skip=2 tokens=3" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal"') do set doc=%A

    for /f "usebackq tokens=2* delims= " %i IN (dir "%doc%" /a /s ^|findstr /i /v "\/"^|findstr /l /v "Pictures Music Video") DO @echo %j&echo.

    To see size of folders in Music.

    for /f "skip=2 tokens=4" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Music"') do set Doc=%A

    for /f "usebackq tokens=2* delims= " %i IN (dir "%doc%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    To see size of folders in Pictures.

    for /f "skip=2 tokens=4" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Pictures"') do set Doc=%A

    for /f "usebackq tokens=2* delims= " %i IN (dir "%doc%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    To see size of folders in Video.

    for /f "skip=2 tokens=4" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Video"') do set Doc=%A

    for /f "usebackq tokens=2* delims= " %i IN (dir "%doc%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    To see size of folders on the Desktop.

    for /f "skip=2 tokens=3" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Desktop"') do set doc=%A

    for /f "usebackq tokens=2* delims= " %i IN (dir "%doc%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    To see size of folders the Windows folder.

    for /f "usebackq tokens=2* delims= " %i IN (dir "%windir%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    To see size of folders the Program Files folder.

    for /f "usebackq tokens=2* delims= " %i IN (dir "%ProgramFiles%" /a /s ^|findstr /i /v "\/") DO @echo %j&echo.

    Disk Cleanup

    The normal way to run Disk Cleanup is to right click the drive in My Computer (Start menu - Computer), then Properties - General tab - Disk Cleanup button.

    Another way is Start menu - All Programs - Accessories - System Tools - Disk Cleanup.

    Disk Cleanup can be started from the command line.

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    To do your main drive.

    cleanmgr %systemdrive%

    To choose which drive to do.

    cleanmgr

    See the last section of this note to see how to supercharge Disk Cleanup.

    System Restore

    In Disk Cleanup above also see the More Options tab. You can delete all but the last System Restore point and see if that is taking up space.

    System Restore uses 15% of the disk space normally. To change click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\cfgand double click DiskPercent and click Decimal and change the value to the percentage you want, You can change it at the command prompt.  Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  To see size of System Restore folder.  You don't normally have access to this folder. You need to take ownership, give administrators permission, then query the size. > > > takeown /f "%systemdrive%\System Volume Information" /a /r /d y> > > icacls "%systemdrive%\System Volume Information" /grant Administrators:f /t /c /q> > > dir "%systemdrive%\System Volume Information" /a /s>  To see current percentage  > > > reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\cfg" /v DiskPercent>  It's hexadecimal. Numbers are 0-9 then a-f. So 0xf is 15. 0x5 is 5, 0x9 is 9, 0xa is 10, 0x14 is 20. To set to a different value.  You can use decimal values to set it. This sets it to 10% (bolded in the example and the last item on the line). > > > reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore\cfg" /v DiskPercent /t REG_DWORD /f /d> 10> To repair the System Restore folder delete it and restart System Restore.> > > sc stop vss> > > takeown /f "%systemdrive%\System Volume Information" /a /r /d y> > > icacls "%systemdrive%\System Volume Information" /grant Administrators:f /t /c /q> > > rd "%systemdrive%\System Volume Information" /q /s> > > sc start vss>Repair the Recycle Bin Sometimes files get lost in the recycle bin. Delete the storage folders. It will be automatically recreated next time you delete a file or open the Recycle Bin. It will delete the Recycle Bin, and files it contains, for all users. Empty the recycle bin.  Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  To see the size of files in the recycle bin It should have one or no files in it if working. There should be a dir (folder) per user. > > > dir %systemdrive%$RECYCLE.BIN\.* /a /s>  To reset the recycle bin > > > rd %systemdrive%$RECYCLE.BIN /s /q> Repair Temporary Internet Files Sometimes files get lost in the temporary internet files folder. Delete the files. It will be automatically recreated next time you download it. It will delete for the current user only. Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  To see the size of files an empty temporary internet files folder > > > RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8> > >  > > > dir "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\.*" "%userprofile%\AppData\Local\Microsoft\Internet Explorer\DOMStore\.*" /a /s>  Then to delete.  Close Internet Explorer and Explorer first. Some files may not delete at this time, they will be able to be deleted later. > > > del "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files" /s /q>  also the DOM store, similar to TIF. > > > del "%userprofile%\AppData\Local\Microsoft\Internet Explorer\DOMStore" /s /q>  Then to see the new size. > > > dir "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\.*" "%userprofile%\AppData\Local\Microsoft\Internet Explorer\DOMStore\.*" /a /s> To see the size of the cache type the followingStart - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).> > > Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content" /v CacheLimit> Use calculator to convert from hex to decimal. Start Calculator (Start - All Programs - Accessories - Calculator) and chooseView menu - Scientific, then View menu - Hex. Enter the value returned above**.**ThenView menu -  Decimal. To convert to windows units divide by 1024 for kilobytes, divide again by 1024 for Megabytes.Set between 50 MB and 250 MB. You can use decimal here. The unit is in kilobytes. The below is 250 megabytes (250,000 x 1024 bytes)> > > Reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content" /v CacheLimit /t Reg_DWord /d> 250000 /f> Delete Files in the System and Service Profiles Temp Folder  The system temp folder is only used when noone is logged in. It is rarely used but never cleaned. Certain services have their own temp folder that is also not cleaned. Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  To list  > > > dir c:\windows\temp C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp /a /s>  To delete  > > > del  C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\.* C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\.* c:\windows\temp\.* /s /f /q> Check Size of Swap File

    As a general rule you want your swap file a little bigger than the amount of memory you have. It grows automatically but doesn't shrink automatically. If using memory hungery programs like video editing it should be bigger. If too big you can shrink it and if pressed for space can be moved to another drive.

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    To see what your usage has been

    wmic pagefile get /format:list

    To see the file size on disk

    dir c:\pagefile.sys /a

    To change size or change drive see Change the size of virtual memory in Start - Help and Support.


    Turn Off Hibernation

    The hiberation file is the same size of installed memory. If not hibernating the computer turn it off and save plenty of disk space.

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    To see if it's on

    If on the file will be found. If off the file won't be there.

    dir %systemdrive%\hiberfil.sys /a

    To turn off

    powercfg -h off

    To turn back on again

    powercfg -h on

    Compact the Various Databases Windows Uses

    You can compact the various databases Windows uses. These are Windows Update, Windows Search, Security Certificates, Windows Mail, Windows Contacts, Windows Calandar, some Windows Live apps, and Internet Explorer ver 10.

    Close Windows Mail and Internet Explorer. Wait a minute for Internet Explorer to release it's file locks.

    To see how much space it taking up type what's below and note the total size (because it will scroll away).

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    dir c:\.edb c:\.msmessagestore c:\WebCacheV*.dat c:\catdb /a /s

    Then to compact

    sc stop wuauserv

    sc stop bits

    sc stop wsearch

    sc stop cryptsvc

    for /r c:\ %A in (*.edb *.msmessagestore WebCacheV*.dat catdb*.) do esentutl.exe /p "%A" /o

    for /r c:\ %A in (*.edb *.msmessagestore WebCacheV*.dat catdb*.) do esentutl.exe /d "%A"

    sc start cryptsvcsc start wsearch

    sc start bits

    sc start wuauserv

    Then to delete some temporary files.

    del c:\.integ.raw c:\TEMPDFRG*.edb /s*

    Then to see the new size and compare to the old size

    dir c:\.edb c:\.msmessagestore c:\WebCacheV*.dat c:\catdb /a /s

    If a program has a file open you can use this procedure to find which program.

    openfiles /local on

    Reboot

    openfiles /query /v|findstr /i "WebCacheV[0-9]*.dat .edb .msmessagestore catdb"

    Remove files updated by Service Packs

    To see how much space it taking up type what's below and note the total size (because it will scroll away). Also note that the total is higher than it actually is.

    This will remove the ability to uninstall the service packs.

    Depending on the service pack Windows was supplied with you may have both, one, or neither of these two files.

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste).

    dir c:\Windows\WinSxS /a /s

    Then type

    VSP1CLN.exe

    COMPCLN.exe

    Then to see the new size and compare to the old size

    dir c:\windows\WinSxS /a /s

     

    Relocate Your Documents

     

    If you have another drive you can move the documents folder to it.

     

    Right click your Documents (or Pictures, Videos, Contacts, Desktop, etc) folder - Properties - Location tab - Move.

    Delete The Thumbnail and Icon Caches

     

    These files may contain thumbnails or icons of long ago deleted files. The files will be recreated as needed.

     

    Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). The desktop and Start menu will briefly disappear.

     

    To see size

     

    dir "%userprofile%\AppData\Local\.db" "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\.db" /a

     

    then to delete

     

    taskkill /im explorer.exe /fattrib -r -s -h "%userprofile%\AppData\Local\.db"attrib -r -s -h "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\.db"del "%userprofile%\AppData\Local\.db" del "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\.db"explorer

     

    to check the new size

     

    dir "%userprofile%\AppData\Local\.db" "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\.db" /a

    Delete Backed Up Files Made By Photo Gallery Windows Photo Gallery makes a copy of any file you change. Click Start - All Programs - Accessories - Run(or press Winkey + R). Type > > > Shell:original images>  Delete ones you don't want. Extending The Size of the Drive If all the space on the disk hasn't all been used it may be possible to extend your drive. Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  > > > diskpart>  then type > select volume c: Then type to see size > > > list volume>  then (it will work if possible or won't if not possible) > > > extend>  then type to see the new size > > > list volume>  then to exit type > > > exit>  If you want advice on extending the partition type the following and paste back the output > > > diskpart > > > list disk> > > list volume> > > select disk 0> > > list partition> > > > select disk 1> > > list partition> > > exit>  To copy the text output right click the window -Mark then select the text and press EnterCompress Files There are two ways to compress files in windows. Zip files and the inbuilt file compression. This is about the inbuilt file compression. Typezip in Start - Help and Support for more info on zipping. Photos, music, and video are already compressed. They may get larger if Windows tries to compress them any further. Also usually a bad idea to compress system files. If you have document or spreadsheet files they can be compressed very well. If you have folders of setup files they may also be good candidates. Web  pages also make good candidates. In Windows Explorer blue filenames means Compressed (this is file system compression not Compressed folders aka zip files). Green filenames means Encrypted.  To turn off coloured filenames, in Explorer -Tools menu (Alt + T) - View tab, and then clear theShow encrypted or compressed NTFS files in color check box. Windows compression, encryption, and security work mostly by apply attributes to a folder, and files in the folder inherit from the folder.  If you have any folders suitable for compression find them in Explorer, right click them -Properties - General tab - Advanced button - Compress contents to save disk space. Choose to apply to all files and folders when asked. To use a command line to compress the files in the Favorites folder. Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  > > > compact /c /s:"%userprofile%\Favorites" *.*>  To set favourites to compress future files added > > > compact /c /s:"%userprofile%\Favorites">  To view compression details of the Favorites folder > > > compact "%userprofile%\Favorites\.*" > Turn off Low Disk Space WarningsTo turn off the feature to show low disk space warnings. Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste).  > > > reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoLowDiskSpaceChecks" /t REG_DWORD /d 1 /f> > > gpupdate /force>Supercharging Disk Cleanup - How Disk Cleanup works- Scheduling Disk Cleanup- Creating custom cleaners To see a list of Disk Cleanup cleaners.Start - All Programs - Accessories - Right click Command Prompt and chooseRun As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosingPaste). @echo.&@echo List of cleaners&@echo ================&FOR /F "usebackq tokens=8 delims=" %i IN (reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches") DO @echo %i List of cleaners ================ Active Setup Temp Folders Content Indexer Cleaner Downloaded Program Files Hibernation File Internet Cache Files Memory Dump Files Microsoft_Event_Reporting_2.0_Temp_Files Offline Pages Files Old ChkDsk Files Previous Installations Recycle Bin Setup Log Files System error memory dump files System error minidump files Temporary Files Temporary Setup Files Temporary Sync Files Thumbnail Cache Upgrade Discarded Files Windows Error Reporting Archive Files Windows Error Reporting Queue Files Windows Error Reporting System Archive Files Windows Error Reporting System Queue Files WLX Thumbnail Cache*

    10+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2014-12-05T09:44:40+00:00

    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.

    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):http://ss64.com/bash/export.htmlwatch - Execute/display a program periodically

    8 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2009-07-09T20:13:21+00:00

    In the absents of any clear information on those switches if you care to run them you will see what they do.  They basically offer various cleaning options and differing output results.  I tried them on my machine and nothing untoward happened but I think I now have a very clean hard drive, and I'm still able to type this message afterward too.

    C:\Windows\system32>cleanmgr /tuneup:1

    C:\Windows\system32>cleanmgr /verylowdisk

    C:\Windows\system32>cleanmgr /setup

    C:\Windows\system32>cleanmgr /lowdisk

    C:\Windows\system32>cleanmgr /SAGESET:1

    C:\Windows\system32>cleanmgr /SAGERUN:1

    7 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2009-07-09T19:16:47+00:00

    More

    http://support.microsoft.com/kb/315246


    Rob - Supporting Member, Cascade Bicycle Club P.O. Box 15165 Seattle, WA. 98115-0165 206-522-3222 and 24 hr hotline 206-522-BIKE http://www.cascade.org

    5 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2010-07-25T21:36:38+00:00

    This does not answer anything. 4 years after the launch of Vista, there is still no documentation about these new switches in Vista/7? This is pathetic. I want to programatically clear the Windows.old folder (known as Previous Windows Installation). How am I supposed to know this if there is no documentation? C'mon Microsoft.

    4 people found this answer helpful.
    0 comments No comments