New
#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:
- https://docs.microsoft.com/en-us/tro...k-cleanup-tool
- https://docs.microsoft.com/en-us/win...f/disk-cleanup
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.
A Disk Cleanup window will open so you can select what options you want on the script 7.
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
Disk cleanup will begin to run
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
Give the task a name and a description.
Hit next. Select the periodicity
Hit next. Select the option
Hit next. Select Action: Run a program
Select next and hit Finish
To test the created task, right click on the created task and hit run
The Disk cleanup will start