Home » All » Windows | All Categories

Published on 07.18.06 by Brent Trahan

Windows XP Automated System Maintenance

Learn how to automate disk cleanup, check disk, and disk defragmenter without any extra software.

A computer is similar to a car in many ways.  One of the ways is a computer needs to be maintained just like your car.  You have to change your oil, rotate your tires, and check your fluid levels on your car on a regular basis for it to run properly and last a long time.  A computer needs a few things done to it on a regular basis to keep it running smooth as well.  This guide will show you how to set your Windows XP computer to automatically take care of it self using the task scheduler and batch files so you don’t have to.

There are three things you should do to keep your computer running smooth.  The first is a disk clean to clean up the trash that accumulates over time.  The second is a disk check to check for any errors on your hard drive.  The third is a disk defragmentation to defragment your hard drive.

The disk clean and disk check should be done once a week.  The disk defragmentation should be done once a month.  If you deal with lots of photos or video on your computer you should defragment your hard drive every two weeks or more.

Disk Cleanup

Normally you would run disk cleanup by going to Start, All Programs, Accessories, System Tools, and click Disk Cleanup.  You would then check off what you want to cleanup and Disk Cleanup would do its thing.

I’ve got a much better way.  I’m going to show you how set your computer to run disk cleanup every week using a scheduled task so you don’t have to.

The first thing you need to do is create a registry entry that tells disk cleanup what you want to clean.  To do this click Start, Run, type CMD in the run box and press enter on your keyboard.  This will open a DOS prompt.  In the DOS window type the following then press enter on your keyboard.

CLEANMGR /sageset:1

A window will appear similar to the screen shot below.


What you are doing is telling your computer every time you run disk cleanup using this registry entry (sageset:1) to clean these files.  I would check off everything other than Compress old files.  Click OK when you are finished.

Now you need to create a scheduled task to run disk clean periodically.  Click Start, All Programs, Accessories, System Tools, and click Scheduled Tasks.  Once the scheduled tasks window is open double-click Add Scheduled Task.  The scheduled task wizard will open.


Click Next.


Click Browse in the next window so that we can find diskclean.  Browse to C:\WINDOWS\System32\ and select cleanmgr.exe.

Please note: If you don’t have a WINDOWS folder look for a WINNT folder.


Check off Weekly and click Next.


Pick a day of the week to run this task and a time to run it.  Click Next.


To run this task you need Administrative privileges.  Type a user account and its password that has Administrative privileges.  By default it sticks the username you are logged on as in the user name box for you.  If you have Administrative privileges (you can install software on your computer) you can use your account.  Click Next.


Check off Open advanced properties… so you can change a few more settings.

Once you’re in the advanced options windows change what’s in the Run box from something like C:\WINDOWS\system32\cleanmgr.exe to C:\WINDOWS\system32\cleanmgr.exe /sagerun:1. Noticed I added /sagerun:1 behind C:\WINDOWS\system32\cleanmgr.exe.

Adding /sagerun:1 tells the cleanmgr program to clean your computer with the settings you set earlier with the sageset:1 command. That is called using a switch.


Click the Settings tab in the advanced options window.

Occasionally disk cleanup will run forever if your computer comes across an error.  I like to stop the task if it runs for 5 hours.  By default it will stop after 72 hours.  I just change the 72 to 5.  If your computer is set to sleep you need to check off Wake the computer…  Click OK when you are finished.

Your computer is now set to run a disk cleanup with the saved settings you set on a weekly basis.

Check Disk

A check disk is a tool for checking for errors and repairing them on your hard drive.  Normally you would open My Computer, right-click the drive you want to perform a check disk on, click Properties, click the Tools tab, click Check Now next to error checking, check off Automatically fix… and Scan for and attempt… and click Start.  If you’re scanning your C: drive it will tell you it can’t scan the drive now, but it can scan it for you the next time you reboot your computer.

I’ve got a better way of doing this.  I’m going to show you how to create a batch file to be launched by the task scheduler that will do all of this for you with no problem.

Open Notepad.  If you just have a C: drive type the code below in the Notepad window.

echo y|chkdsk C: /f/r
shutdown /r

The code above will tell your computer to run a check disk and fix any errors it finds automatically.  Your computer will give it an error saying it can’t get full access to the C: drive but it can set the task to run the next time the computer is rebooted.  The batch file will accept and then reboot your computer.

If you have more partitions or hard drives (example E: and F: drive where you save things) than just the C: drive you can scan those too by using the code below in the Notepad window instead of the code above.

chkdsk E: /f/r

echo y|chkdsk C: /f/r
shutdown /r

If you have multiple drives like E: F: and G:, just add a new line for each drive letter.  The C: drive must be the last drive to be scanned because your computer must be restarted to scan your C: drive.  Make sure that portion of the code stays at the bottom of the batch file.

Once you are finished creating the batch file save the file by clicking save as, change Save as type to All Files, then type checkdisk.bat in the file name box.

Open the task scheduler and create a new task to run the checkdisk.bat file once a week (every Sunday morning at 4am) just like you did for the disk cleanup task.

Defragment Your Hard Drive

Windows is very sloppy when it comes to handling files.  Instead of saving them where they belong on your hard drive Windows sticks them where ever it’s most convenient.  Over time this will slow your computer down.

Normally you would click Start, All Programs, Accessories, System Tools, and click Disk Defragmenter.  Once the disk defragmenter is open you would select a drive you want to defragment and click defragment.

Double-click Add Scheduled Task in the task scheduler.


Click Next.


Click browse.


Browse to C:\WINDOWS\system32\ and select defrag.exe.  Click Open.

Note: If you can’t find defrag.exe in C:\WINDOWS\system32\ try looking in C:\WINNT\system32\.  Some systems install their system files there.


Select Monthly, and then click Next.


Set it to happen at 4am on the first Monday of ever month like the screen shot above.  Make sure the multiple tasks you are creating are not overlapping each other.


Give the scheduled task wizard a user account with Administrative rights just like you did with the disk cleanup task.


Check off Open advanced properties… and click Finished.


Next to run is C:\WINDOWS\system32\defrag.exe.  Add C: behind C:\WINDOWS\system32\defrag.exe to automatically defragment the C: drive.  Add a D: to defragment the D: drive and so on. An example would be C:\WINDOWS\system32\defrag.exe C:.

Now your computer is set to take care of itself.

Still need help? Ask your computer question now.

Related Guides:

6 Responses to “Windows XP Automated System Maintenance”

Subscribe to this guide's comments RSS feed.

  1. LinuxUser says:

    This ONLY aplies to Windows The need for defragging due to their badly thought out filesystem

  2. LinuxSux0rs says:

    Only applies to windows my A**. You Linux users are such immature, obsessive whiners. Linux is nothing more than a geek OS. Linux will never be anyting more than a geek OS. Deal with it.

  3. Brent Trahan says:

    Watch the language please.

  4. Dino says:

    Thanks for the tips! This helped me a lot.

  5. Manish kumar says:

    Why the c: drive not open in duobble click it show the auto error?

  6. Dirt Speck says:

    All hard drives need defragmentation to maintain
    optimal performance, regardless of the OS!

    End of story.

Leave a Reply

Subscribe to this guide's comments RSS feed.

Microsoft Windows is a registered trademark of Microsoft Corporation. Microsoft Corporation in no way endorses or is affiliated with MAXIMUMpcguides.com. All other products mentioned are registered trademarks of their respective companies. MAXIMUMpcguides IS NOT RESPONSIBLE for any damage or data loss to your computer from using this web site. All information on MAXIMUMpcguides is provided on an AS IS basis with NO WARRANTIES.

Copyright 2006-2019 Brent Trahan. All rights reserved.