See "How to Automate the Disk Cleanup Tool in Windows XP"
(http://support.microsoft.com/?kbid=315246).
For error checking: type
CHKDSK /?
at a DOS prompt, for defragging type
DEFRAG /?
and then write batch files or create shortcuts with the proper
command-lines.