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!

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.

End of Article

   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
Command Prompt Tricks

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

New Microsoft/Yahoo! Deal? No

On Sunday, the Times of London reported that Microsoft had renewed talks with failing Internet giant Yahoo! and would manage its search engine for 10 years, while Yahoo! would retain control of its email, messaging, and content services. This report ...

How can I stop and start services from the command line?

...


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