How to automatically run Disk cleanup on Windows 7, 8.x and 10


  1. Posts : 6,330
    Windows 11 Pro - Windows 7 HP - Lubuntu
       #1

    How to automatically run Disk cleanup on Windows 7, 8.x and 10


    How to automatically run Disk cleanup on Windows 7, 8.x and 10 (and maybe on 11)

    This tutorial is based on two Microsoft docs:


    Some text has been copied from them and pasted into this tutorial.

    One axiom proven time and again in the world of computers is that regardless of the size of your computer's storage capacity, you will eventually fill it up. While the average size of a computer's hard disk has increased dramatically over time, applications have also grown accordingly, leaving users looking for ways to create more free hard disk space. Available space is also reduced by the many temporary files that applications create for backup or performance reasons. When disk space becomes low, it becomes necessary to reduce the amount of space used by applications. Disk space can be freed by deleting useless files.
    Files that are good candidates for cleanup include:

    • Files that the user will never need again.
    • Temporary files that exist only for performance reasons.
    • Files that can be restored, if needed, from an installation CD.
    • Data files that have possibly been superseded by newer versions, such as old backup files.
    • Older files that have not been used in a long time.

    As part of a maintenance routine, disk cleanup and backups should be done regularly.
    This tutorial will show how to run disk cleanup periodically and automatically.

    Part 1: Create a script of what disk cleanup should periodically and automatically clean.

    Open a CMD window (%windir%\system32\cmd.exe) as administrator and type:
    cleanmgr.exe / sageset:n (n can be any number from 0 to 65535. It will be the script number)

    On my example n will be 7.
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-sageset.jpg

    A Disk Cleanup window will open so you can select what options you want on the script 7.
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-disk-set.jpg

    When selection is done, hit OK. You have just set the options for script 7.
    You can rerun cleanmgr.exe / sageset:n to modify the script n.

    You can create different scripts (up to 65535). These scripts are saved on the register on HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\
    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:7 command, a registry value Stateflags0007 is added. The registry value can be set as one of the following values.

    • If the option box is not selected, the value is 00000000.
    • If the option box is selected, the value is 00000002.



    Next step is to test the script.
    - Open a CMD window as administrator and type:
    cleanmgr.exe / sagerun:7

    How to automatically run Disk cleanup on Windows 7, 8.x and 10-sagerun.jpg

    Disk cleanup will begin to run
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-disk-run.jpg

    Part 2:
    Create a Schedule task.
    Open Task Scheduler (%windir%\system32\taskschd.msc /s)
    On the left panel, select Task Scheduler Library. You can create a specific folder for the disk cleanup or you can place it on the root.

    Right click on the center panel and select Create Basic Task
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-create-task1.jpg

    Give the task a name and a description.
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-task-name.jpg

    Hit next. Select the periodicity
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-periodicity.jpg

    Hit next. Select the option
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-periodicity_option.jpg

    Hit next. Select Action: Run a program
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-program.jpg

    Select next and hit Finish
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-finish.jpg

    To test the created task, right click on the created task and hit run
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-run.jpg

    The Disk cleanup will start
    How to automatically run Disk cleanup on Windows 7, 8.x and 10-disk-run.jpg


      My Computers


  2. Posts : 632
    Linux Lite
       #2

    great job
      My Computers


  3. Posts : 6,330
    Windows 11 Pro - Windows 7 HP - Lubuntu
    Thread Starter
       #3

    f23948 said:
    great job
    Thanks
      My Computers


  4. Posts : 8,111
    windows 10
       #4

    Most now run storage which you can set to run with a few clicks
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 09:17.
Find Us




Windows 10 Forums