I wrote this script with AutoIT (www.autoitscript.com)
You can easily compile autoit code for external uses in batch files. check out the site above.
You could start /wait this compiled code below to automate tasks.
I have also created a similar script for all profiles in CCleaner check out my other posts...
#include <Array.au3>_Defrag()
Func _Defrag()
$DRV_Letter = DriveGetDrive(“FIXED”)
If Not @error Then
For $i = 1 To $DRV_Letter[0] $PRC = RunWait(@SystemDir & '\df.exe ' & $DRV_Letter[$i], "", @SW_HIDE) ProcessWaitClose($PRC) Next
EndIf
EndFunc ;==>_Defrag
-MBK (AIM=IllMBKllI)