Registry Parameters for /Sageset and /Sagerun
The file-selection settings you configure reside in the client's HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\
Windows\CurrentVersion\Explorer\VolumeCaches registry key. Under that key are subkeys that correspond to the available selections in Disk Cleanup. Within those subkeys are StateFlags entries that correspond to the number you provided to the /sageset parameter. For example, Figure 2 shows the Internet Cache Files subkey. In this subkey, note the StateFlags0100 entry, which I configured by following the instructions I previously gave you, and the StateFlags2112 entry, which I set in another /sageset operation. The DWORD value of 2 tells Disk Cleanup to delete the Internet cache files when I run the Cleanmgr command with the /sagerun:2112 parameter. A StateFlags entry with a DWORD value of 0 tells Disk Cleanup to not delete the files associated with the current registry subkey.
The significance of providing these details is that you can configure registry settings on your clients through one of many methods so that the clients have a consistent array of StateFlags values. You can then use a logon script or scheduled task to have all your clients perform the same cleanup operations.
Before I show you how to use Disk Defragmenter, I want to briefly mention one other Disk Cleanup option: file compression. To save disk space, you can use Disk Cleanup to compress old files. However, given today's disk capacities, you might not find many arguments for compressing files. So, whether to compress or not compress is a policy decision that your organization has to make.
Disk Defragmenter
Unfortunately for Win2K Pro users, one limitation of the built-in Disk Defragmenter tool is that you can't deploy it regularly through a script or scheduled task. Fortunately, Microsoft addressed this limitation in XP by adding the Defrag.exe command. The command's basic syntax is
defrag.exe volume
where volume is the disk volume or mount point you want to defragment. Besides the mandatory volume argument, the defrag.exe command has three optional parameters: /a (analyze only), /f (force defragmentation), and /v (verbose output).
To automate Disk Defragmenter, you must use the /f parameter. This parameter tells Disk Defragmenter to proceed with its operations, even if disk space is below 15 percent or if current fragmentation levels don't warrant a defragmentation. Specifically, you can use the command
defrag.exe C: /f
in a batch file or scheduled task. Because of the resource-intensive nature of defragmentation, you should schedule the batch file or task to run during off-hours. Don't run Disk Defragmenter through a logon script.
To keep an eye on how the defragmentation is running, you can write a script that takes advantage of the ERRORLEVEL values that the defrag.exe command returns. ERRORLEVEL values can notify you of low disk space or other problematic conditions that might prevent Disk Defragmenter from completing its mission. They can also notify you of successful defragmentation operations. The Microsoft article "How to Provide Event Logging for the Disk Defragmenter Utility with Windows Script Host" (http://support.microsoft.com/?kbid=294743) tells you how to use Windows Script Host (WSH) to extrapolate the ERRORLEVEL values and create entries in the Windows event log.
If your clients are running Win2K Pro but you still want to automate defragmentation, you might consider using a third-party utility. Even if your clients are running XP, you might consider a third-party utility if you want additional features and better scheduling capabilities. Available defragmentation utilities include Executive Software's Diskeeper 8.0, NORTHERN Parklife's O&O Defrag 6.0, Raxco Software's PerfectDisk 6.0, and Winternals Software's Defrag Manager 2.5.
Proactive Maintenance for Performance and Stability
Although disk-space problems are less of a concern than they used to be, other benefits result from keeping your users' disks clean and defragmented. An automated approach to regularly removing unneeded files and organizing the remaining files is akin to the old adage, "An apple a day keeps the doctor away." And, because you are the proverbial doctor, you'll have time to concentrate on more important tasks.