Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


June 2004

Don’t Nag—Just Do It

Users not cleaning up and defragmenting their hard disks? Do it for them the easy way.
RSS
Subscribe to Windows IT Pro | See More Windows 2000 Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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.

   Previous  [1]  2  Next 


Reader Comments
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?

Mark June 03, 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.

Schell August 21, 2004 (Article Rating: )


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.

RobinHood December 01, 2004 (Article Rating: )


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.



briand@kaplantrucking.com December 02, 2004


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

Anonymous User February 16, 2005 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Microsoft Delivers Service Pack 2 Beta 2 for Vista, Server 2008

Microsoft on Tuesday announced the availability of the Beta 2 version of Service Pack 2 (SP2) for Windows Vista and Windows Server 2008. Since both operating systems were developed from the same code base, they have a common servicing structure and thus ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events Storage Consolidation for Your Microsoft Applications: Reducing Cost and Complexity

Optimize your VMware Infrastructure with the New Releases from the Symantec Backup Exec Family

Windows, Unix, Linux Interoperability

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing