Talking tech since 2003

As any Windows user knows, regular computer maintenance is essential to a speedy and reliable Windows installation.  While most people know how to perform basic maintenance such as disk cleanups, file compressions, disk de-fragmentation, etc, the fact of the matter is that the hustle and bustle of daily life often leads us to forget about such tasks.  Because of this, people often end up going for months without maintaining their computers, and ultimately end up with a bogged down machine.  While there are some strategies to make a re-install go easier, the fact still remains that one is much better off preventing any issues before they occur.

There are three components of automated maintenance that this tutorial will cover.  The first component, being disk cleanup, requires you to firstly set a setting within Windows that tells it what exactly you want it to do during the automated process.  To do this, you will want to go to either the Run or Command Prompt window and type “cleanmgr /sageset: 1”.

The next screen that pops up will look very similar to the standard Disk Cleanup utility, however it will simply be a settings window that will let you choose what options you want the program to perform when it is launced through the script we will create later in this article.  What you choose here is really up to you.  For my automated configuration, I choose to do everything except empty my recycle bin.

Now, the next step is to simply create a script that, when executed, will perform the given maintenance commands; carrying out a series of events in the order given.  To create this script, simply fire up Notepad (or another text editor), and insert the following code;


@echo off
defrag.exe C:
cleanmgr.exe /sagerun: 1
echo y | chkdsk /r
shutdown -r -t 30

Now, you’re probably wondering what this does.  The first line (“@echo off”), tells the script not to display the commands that it is using.  While this simply makes the script less confusing to someone who is looking at it running, it is by no stretch of the imagination a required line.

The second line (“defrag.exe C:”) runs the command-line based disk de-fragment in Windows.  The parameter “C:” tells it to defrag the C: drive in Windows.  It you have multiple drives, you may want to add additional lines to de-fragment them as well.

The third line simply tells the script to run the Windows Disk Cleanup tool, and to use the settings you specified earlier.

The fourth line schedules a disk check on your system for the next restart.  Ideally, one would not restart the computer for the process, however because the drive is active, the system must be restarted in order for the disk-check to work.  Simply running “chkdsk /r” would require the end-user to be present to hit the “Y” button to confirm said action.  However, in creating a truly automated script, using “echo y | chkdsk /r” tells the script to execute the “chkdsk /r” command and automatically approve the action.

The last line goes ahead and initiates the system restart.  Because of the command before it, a disk-check will take place during the restart process.

Once you’ve completed the script to your liking, including any additional commands you may need for software updates, etc, you will want to save this file as “maintenance.bat” in your C: drive.


Lastly, you will want to tell Windows to execute the script periodically at a given time.  To do this, go you to your Control Panel, switch to classic view, and find the “Scheduled Tasks” menu.  From there, double click on “Add Scheduled Task”.  This will initiate a wizard that will first ask you what task you want to run.  At this point, you will simply need to navigate to the “maintenance.bat” file that you created earlier.


On the next screen of the wizard, you will be asked how often you want the task to occur.  Personally, I choose to have mine done “weekly”, and then on the next screen choose Saturday mornings at 3:00AM.  However, this ultimately is a decision that is up to you, and should be a time that your computer will be on and that you will not be using it.


The last screen will simply ask you to specify the user as whom you will want to run the task as.  You simply need to use a computer administrator’s credentials (user name and password), and you’ll be all set.

With this automated task, you’ll never again have to worry about remembering to do routing maintinance in Windows.

If you have any suggestions on automating computer maintenance, or if you simply need help in any are of tech, feel free to pop in to the chat room.

You've successfully subscribed to BestTechie
Welcome back! You've successfully signed in.
Great! You've successfully signed up.
Your link has expired
Success! Your account is fully activated, you now have access to all content.