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, error, and setup files with limited value. One way to remove these space-hogging files is to create a Windows Scheduled Task with the disk cleanup tool to delete files regularly. Once you understand scheduled tasks, you’ll start automating other maintenance items.
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 files that don’t need to be securely erased. 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 Windows operating system. This gem of a program is called cleanmgr.exe.
You can run the program using its path, 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.
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 box, 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 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 Task Scheduler
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 daily or on 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 Task Scheduler.
- Select Task Scheduler from the results.
- Click Create Basic Task… to start the Task Scheduler Wizard.
- Provide a name for your task.
- Enter some description about the task. Click Next.
- Set your time trigger using 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.
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. If anything is wrong such as password errors, I can correct it 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.