Admin Tip #12: XP Defrag is commandline capable and schedulable

Hits: Failed to execute CGI : Win32 Error Code = 3



Windows XP defrag program has a commandline interface. This means you can use XP's scheduler to automate the defragmenting of your partitions. To get the options for defrag:

C:\>defrag

Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.
Usage:
defrag  [-a] [-f] [-v] [-?]
  volume  drive letter or mount point (d: or d:\vol\mountpoint)
  -a      Analyze only
  -f      Force defragmentation even if free space is low
  -v      Verbose output
  -?      Display this help text

When I defrag the C: partition:

C:\>defrag c: -f
Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.

Analysis Report
    4.98 GB Total,  2.69 GB (54%) Free,  4% Fragmented (8% file fragmentation)

Defragmentation Report
    4.98 GB Total,  2.69 GB (54%) Free,  0% Fragmented (0% file fragmentation)
In the following, I schedule the C: partition to be defragged at 6pm, D: at 7pm, and E: at 8pm.

C:\>at 18:00 /interactive /every:M,T,W,Th,F,S,Su "defrage c: -f"
Added a new job with job ID = 1

C:\>at 19:00 /interactive /every:M,T,W,Th,F,S,Su "defrage d: -f"
Added a new job with job ID = 2

C:\>at 20:00 /interactive /every:M,T,W,Th,F,S,Su "defrage e: -f"
Added a new job with job ID = 3

C:>at
Status ID   Day                     Time          Command Line
-------------------------------------------------------------------------------
        1   Each M T W Th F S Su    6:00 PM       "defrage c: -f"
        2   Each M T W Th F S Su    7:00 PM       "defrage d: -f"
        3   Each M T W Th F S Su    8:00 PM       "defrage e: -f"