In Windows XP, go to Start Menu > Settings > Control Panel > Scheduled Tasks go through the wizard, selecting C:\Windows\System32\defrag.exe to run. At the end, in the advanced options make it run
C:\Windows\System32\defrag.exe c: -f
or D: or whatever your drive name is.Microsoft provides documentation on the command line defrag:
defrag volume [-a] [-f][-v] [-?]
volume: The drive letter or a mount point of the volume to be defragmented
-a: Analyze only
-f: Forces defragmentation of the volume regardless of whether it needs to be defragmented or even if free space is low
-v: Verbose output
-?: Display the help text
volume: The drive letter or a mount point of the volume to be defragmented
-a: Analyze only
-f: Forces defragmentation of the volume regardless of whether it needs to be defragmented or even if free space is low
-v: Verbose output
-?: Display the help text
source(s): http://support.microsoft.com/kb/283080