Subscribe to Windows IT Pro
May 27, 2004 12:00 AM

Don’t Nag—Just Do It

Users not cleaning up and defragmenting their hard disks? Do it for them the easy way.
Windows IT Pro
InstantDoc ID #42597
Rating: (3)

With the disk capacities available in today's desktops, you probably have few if any hassles with clients that have run low on disk space. Without such hassles, it's easy to forget about disk cleanup and other general maintenance tasks necessary to keep Windows XP and Windows 2000 Professional clients running smoothly and efficiently.

Disk fragmentation and superfluous temporary files can have a detrimental impact on users' systems. XP and Win2K Pro include the Disk Cleanup and Disk Defragmenter tools, but getting users to run those tools is typically an exercise in futility. And if your IT staff is running as thin as most are these days, you probably won't get many volunteers to run these tools for users. In XP, you can automate both Disk Cleanup and Disk Defragmenter and use the built-in task scheduler (i.e., Scheduled Tasks) to run cleanup and defragment operations regularly. In Win2K Pro, you can automate Disk Cleanup but not Win2K Pro's Microsoft Management Console (MMC)-based Disk Defragmenter.

Because deleting unused files before defragmenting a disk is common sense and the best practice, I show you how to automate the Disk Cleanup tool first. Before I begin, though, I should mention that the potential for data destruction exists when you perform a defragmentation. If you don't feel secure in automating the defragmentation process for your clients, you're better off performing the task manually for them.

Disk Cleanup
To clean up unnecessary files in XP and Win2K Pro, you can use Disk Cleanup. You've probably used this tool through its GUI, but you can also run the tool from the command line. You can use command-line parameters (aka switches) to tell Disk Cleanup to delete certain types of files. At first, the command-line process might seem overly complex, but after you get past the learning curve, it makes sense.

When you run Disk Cleanup from the command line, you use the Cleanmgr command, which has three parameters: /d, /sageset, and /sagerun. Using Cleanmgr to automate file cleanup is a two-step process. First, you run the command with the /d and /sageset parameters to specify a set of files to delete, then you run the command again with the /sagerun parameter to perform the actual cleanup.

The /d parameter lets you select the drive on which you want to delete unnecessary files. The /sageset parameter lets you select the types of files you want to delete (e.g., temporary setup files, old Chkdsk files) and associate that set of file types with a unique number. You use the /d parameter with the /sageset parameter, following the syntax

cleanmgr /d X: /sageset:n

where X is the letter of the target drive and n is a unique numeric value from 0 to 65535. Disk Cleanup stores the set of files and its associated number in the registry.

You use the /sagerun parameter to run Disk Cleanup against the set of files you specified with the /sageset parameter. You use the syntax

cleanmgr /sagerun:n

where n is the number representing the set of files you want to delete. The /d parameter doesn't apply when you use the /sagerun parameter.

Let's try setting a group of files to delete, then run Disk Cleanup against those files. Open a command-shell window. Type

cleanmgr /d C: /sageset:100

and press Enter. Figure 1 shows the Disk Cleanup Settings dialog box that appears. In this dialog box, select the types of files you want to delete. When you click OK, Disk Cleanup will save this group of files as set number 100 in the registry. Now type

cleanmgr /sagerun:100

to automatically run the Disk Cleanup tool against those files. As you can see, this process is pretty simple.

File and Frequency Options
Depending on your user environment, you might want to perform light-duty cleanups on a frequent schedule or schedule more intense cleanups at less frequent intervals. As you consider the types of files you can specify for cleanup, you'll probably identify a few general classifications. My personal classification terms for the file-deletion groups are temporary files, operational files, and discretionary user files.

Temporary files. Temporary setup files, temporary Internet files, Windows temporary files, and temporary offline files all fall into the temporary files group. You're safe deleting the files in this group without hesitation.

Operational files. Old Chkdsk files and catalog files for the content indexer fall into the operational files group. These files are also safe to delete.

Discretionary user files. Downloaded program files, files in the Recycle Bin, and offline files fall into the discretionary user files group. Depending on your environment, these files might be off limits for an automated deletion scheme. Downloaded program files, which are in the %systemroot%\Downloaded Program Files folder, are typically ActiveX controls and Java applets that the browser downloads when you browse a site that uses them. No real harm occurs when you delete these items because the browser can download them again. However, you must consider frequency of use and the size of the controls or applets before deleting them.

Different users have varying approaches to using the Recycle Bin. Some users are barely aware of its existence, whereas other users access it daily as if it were a typical file-system folder. Because of the latter group of users, you need to be aware of your users' Recycle Bin habits before you automate the deletion of its contents.

The offline files store contains copies of network files that have been made available offline either manually by the user or through a Group Policy setting. Unless you have a problem with users creating excessive offline resources without merit, you should leave these files alone.

After you understand the ramifications of the available file selections, you need to decide how frequently you want to carry out certain deletion operations. For example, like many organizations, you might find that deleting temporary files once a week is adequate but deleting discretionary files once a week is overkill. If you need to perform certain deletions more frequently than others, you have to create multiple selection sets, providing a unique number to each with the /sageset parameter. Keep track of the numbers and their associated settings because no simple way exists to recall that information.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Feb 16, 2005

    Is there a quite switch so that users dont know you are running the process?

  • briand@kaplantrucking.com
    8 years ago
    Dec 02, 2004

    It was mentioned in the article that you cannot schedule Defrag to run automatically on Windows2000. You can't execute dfrgntfs.exe from a command prompt, you can’t use a batch file, and you can’t use the task scheduler to schedule the process. We did find a VBScript on the Internet however that will allow you to do this.

    To implement:
    1. Copy the attached file to a location of your choosing. (since I could not attach the file, feel free to contact me and I'll send you a copy (briand@kaplantrucking.com)

    2. Rename the extension to ‘vbs’.
    3. Open Task Scheduler and set up a new scheduled task to your liking to kick off this file.

    Basically it opens Disk Defragmenter and sends keys to the application. I altered the script to defrag the second drive on the list. This was necessary because when Dell made my computer they created it with a 55meg Unmounted, FAT volume. This volume appears first on the list of drives. If your computer is not configured the same way you will need to comment out that code from the script. The code is commented and finding it should not be a problem.

  • Robin
    8 years ago
    Dec 01, 2004

    As a workaround for the "Compress old files" problem, use the registry editor to go to

    HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Compress old files

    then do one of the following:

    a) delete the key in its entirety; or
    b) invalidate the GUID in the "(Default Value)" key by adding the word "Disabled: " in front of it (or any other word that makes sense to you). If for some reason you don't want to use .reg files to delete/re-add the key, this allows you to quickly enable/disable the option, without the risk of losing the GUID.

    As always, don't forget to backup your registry, or at least that key, before you make changes.

  • MICHAEL
    8 years ago
    Aug 21, 2004

    MSKB 837642 describes why automating Cleanmgr doesn't work with Windows Server 2003. According to Microsoft, it's because sageset doesn't create the needed registry values. I've tried manually creating the StateFlagsxxxx registry values, and that seems to work OK. You can also contact Microsoft for the specific hotfix that's supposed to fix this. Hopefully it will be addressed in SP1.

    By the way, I've often found in WinXP/2003 that cleanmgr does not purge files in the Recycle Bin if they're owned by a different user than the account underwhich cleanmgr was run.

  • mark
    8 years ago
    Jun 03, 2004

    You mention little about the File Compression utility except in today's market it's really not needed. This is so true. The process, however, takes too long to complete to where I cancel it instead. Is there a way to turn off scanning for files avail for compression?

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.