It is the beginning of a new month: there are many things we have to take care of: updating our schedules, cleaning our homes for junk and paying for bills, of course.
In today's post, I saw it necessary to consider thinking of cleaning up our systems on this first day of August. So we are going to talk of a useful tool called the disk cleanup tool on Windows.
Have you ever wondered why out of the blue you got a message from the operating system about you running out of space? This is a clear indication that it may be time to clean up junk.
The solution is to run a built-in utility called disk cleanup. In the following sections, I will show you how you can run it, and how to add it to the Windows Task Scheduler.
A disk cleanup utility is a tool that is used to remove excess files from a computer drive. The cleanup utility makes it easy for you to locate possible files you might not have taken time to check that are taking up your disk space.
Starting the Disk Cleanup tool
You can launch the Disk Cleanup tool in three ways:
Running from the Drive
A second way which I sometimes find as easy is to simply navigate to the drive you want to clean up and launch the utility from there.
For instance, you can navigate to the local disk such as C: or any of its partitions like E:, F: etc.
Press ALT-ENTER keys on the drive. This opens the properties of the drive.
Under its general settings, you will see the Disk Cleanup tool button. Click it to launch the cleanup utility.
Running from the Command Line
To run the disk cleanup utility from the command line, just open the command line prompt.
When it appears, type "Cleanmgr" and press Enter to launch it.
However, it is important to understand that being able to run programs from the command line is what makes it possible to set this in a task scheduler. This is because the cleanup utility has some optional arguments you can pass to it such as /d to indicate the drive letter you want to clean. For example:
Cleanmgr /d E
will clean the E: drive. So the "d" switch can be understood as meaning drive. However, when you use the /sagerun switch explained below, you do not indicate the /d switch.
Other switches are:
|/sageset||For setting the options of the disk cleanup utility in the registry to be read by any automating tool such as the task scheduler.|
|/sagerun||For silently running the cleanup tool. To do that, of course, it must have the settings it has to use. These are what we set with the /sageset. Remember that when you use the /sagerun, you do not indicate the /d option.|
Automating Disk Cleanup
To automate the disk cleanup, you must be able to do task scheduling first.
But before setting up the task schedule, use the command line and launch the cleanup utility and configure how it has to be run. You do it like this:
where n is any number from 0 to 65535. This number is what will be stored in the registry. You will refer to this number in a task, so that the task scheduler runs your disk cleaning tool reading this number.
So let us work with an easy number such as 1. On the command line, type:
After running this command, the cleanup utility will require you to check all those files you want to be cleaned.
After making sure that you have all the settings right, click OK and your settings will be stored in the registry with the number 1: which will be read by the /sagerun option.
So to automate your disk cleanup, say every month, just open the task scheduler. Under the new action,
- choose "Run Program".
- In the box that appears, type cleanmgr.
- Under the optional arguments, enter /sagerun:1
- Now click finish.
Don't forget to set the trigger to monthly, and set the day of the month this task has to run. Preferably the last day of the month may be suitable for this action.
The /sagerun switch is what will make the disk cleanup utility to run, the :1 option is the value that will be read from the registry you set with the /sageset:1 on the command line.
To use the Disk Cleanup utility
Now that we know how to launch the tool, automate it, how do we use it?
The disk cleanup is relatively easy to use: it is just a dialog box that displays how much space you are going to reclaim from your drive after a cleanup operation.
You move through its fields with a TAB key.
The first field is labelled, "files to delete". This field displays the different types of files that can be cleaned from your system. Press the checkmark against the file category that has to be cleaned up.
You move through this field with either up or down arrow keys. If you hear the field you want, press the spacebar to check it.
If you are not sure what the file category is all about, pressing the TAB key to the next field will show you the description.
So you see, this utility is simple to use that it does not require many pages of explanations.
Suffice to say that after choosing all the fields you want cleared, press the TAB key and press the OK button to start the cleaning operation.
I hope you have found his post useful in your maintenance task. Until next time, have a pleasant cleanup experience!