Even though hard drives are larger and cheaper than ever, we still need to clean up our PC. Apart from the files we create, Windows creates others such as temp files, error files, and setup files that have limited value. One way to remove these space-hogging files is to create a Windows 10 scheduled task with the disk cleanup tool to regularly delete files. Once you understand scheduled tasks, you’ll start automating other maintenance items.
info This tutorial was originally written for Windows 7. It has been updated to reflect Windows 10 task scheduler.
There are many ways to clean up your drive. Perhaps, the best-known method is to highlight files and hit delete or drag them to the Recycle bin. This process works well for files we recognize or created. Behind the scenes, there are countless files created when you install software and browse the web. You don’t consciously think about these files since you never gave them a name. They are ancillary stuff occupying space and possibly slowing your computer.
Defining the Disk Cleanup with Sagesets
Microsoft added a disk cleanup tool to various versions of the operating system. The tool is buried under several layers, but you can get to it from Start | All Programs | Accessories | System Tools. This gem of a program is called cleanmgr.exe.
You can run the program using the path mentioned above, but it requires that you select a drive and settings each time you use it. A more efficient way is to create a sageset that maintains your settings. You might think of a sageset like a profile written to the Windows registry. Rather than providing a profile name, Windows uses a number. You can have up to 65,535 sagesets.
To Create a Windows Disk Cleanup Sageset
- In the Search bar next to your Windows key, type cmd.
- Select Command Prompt from the results.
- In the Command Prompt window, type cleanmgr /sageset:1
- Press Enter.
- In the Disk Cleanup Settings dialog, check the delete options you prefer.
- Click OK.
Since you can have many sagesets, you could create one set to run daily and another to run weekly based on your usage. You just assign a different number and settings such as /sageset:2
One cautionary note is I wouldn’t delete Office Setup Files unless you’re short on disk space.
Automate Disk Cleanup with Windows 10 Scheduled Tasks
Once you’ve created your sageset which tells Windows which files to delete during an automatic disk cleanup, you need to define when this process should run. This is done using the Task Scheduler tool.
The tool is another one that is rarely used. It allows you to run a program on a predefined basis whether it is a daily or a one-time basis. It works with many programs and not just cleanmgr.exe.
For our purposes, we will use it to run cleanmgr.exe with our defined sageset. This is done using the advanced features and the sagerun command.
To set a Scheduled Task with Sagerun
- In the Search bar next to your Windows key, type Scheduled tasks.
- Select Scheduled Task from the results. It will show with Control Panel underneath.
- Click Create Basic Task… to start the Scheduled Task Wizard.
- Provide a name for your task.
- Enter some description about the task.Click Next.
- Set your time trigger uusing the radio button selections. Click Next.
- Add in your additional time options based on your previous section. Click Next.
- For the Action option, select Start a program.
- Click Next.
- You will not see cleanmgr.exe listed so you need to click Browse.
- Navigate to the folder containing your program. In our case, it’s in the Windows > System 32 folder.
- Type cleanmgr.exe in the File name textbox and click Open.
- Type /sagerun:1 in the Add arguments (optional) textbox.
- Click Next.
- A task summary will appear with your information about the scheduled task.
- Click Finish.
info Alternatively, you could type Task Scheduler.
When the designated time occurs, your custom cleanmgr program should start. If it doesn’t, open Scheduled Tasks and see if anything shows in the Status column.
Usually when I create a scheduled task, I test it by using a time that is 5 minutes out and watch the results. This way if anything is wrong such as password errors, I have the opportunity to correct sooner than later. Once the task runs to my liking, I edit the times by right-clicking and selecting properties from the Scheduled Tasks.
After you get the gist of how these tools work, you’ll probably set up scheduled tasks for other items besides disk cleanup. Although this trick may not stop you from needing another hard drive, it can delay that purchase and buy you some extra time.
If you have an older version of Microsoft Windows, you can follow this article for help.