Tip 17: Scheduled Automatic Defragmentation in Windows 2000

Windows 2000 features a nice Defragmentation tool, a slightly honed down version of Diskeeper. A major drawback with this tool as opposed to its commercial counterpart is the fact that it needs to be run manually and lacks a scheduling facility.

However, using a little known Microsoft utility called ScriptIt it is easily possible to schedule a job that defragments your disk(s) at your convenience: scriptit script.txt

ScriptIt is a program that enables you to simulate keystrokes that are being sent to a particular Program running in a particular Window. The .zip file provided contains some examples, notably the script below that takes care of defragmenting the C and D drive on a system using the standard Windows 2000 Defragmentation tool.

ScriptIt "language" is simple and easy as the example illustrates and can easily be adapted to your particular needs.

[Script]
REM run the standard defrag tool
run=mmc.exe c:\winnt\system32\dfrg.msc

REM in the window titled Disk Defragmenter
REM simulate pressing Alt, Action, Defragment on the selected drive (=C)
Disk Defragmenter=!AD

REM in the window titled Defragmentation Complete
REM simulate pressing the TAB en ENTER keys
Defragmentation Complete={Tab}{Enter}

REM in the window titled Disk Defragmenter
REM simulate pressing Alt, Action, Defragment on the now selected drive (=D)
Disk Defragmenter={Down}!AD

REM in the window titled Defragmentation Complete
REM simulate pressing the TAB en ENTER keys
Defragmentation Complete={Tab}{Enter}

REM in the window titled Disk Defragmenter
REM simulate pressing Alt, F4 to exit the mmc
Disk Defragmenter=!{F4}


Alternatively, you can also quickly start Defrag from the context menu when you right-click a drive.