I did glue a few pieces of this vbs script and tested it on one machine.It quickly exited cause the machine did not need defrag.I have put it the piece where it scans each drive and analyses and defrag if needed.It will work regardless.if you send me mail I will send you zip file or you can copy the text,save and run.Watch for line breaks and I hope this will help.Below is the script text
StrComputer = "."
Set objWmiService = Getobject("Winmgmts:\\" & Strcomputer & "\root\cimv2")
Set Coldisks = ObjWMIService.Execquery("SELECT * From Win32_logicalDisk WHERE DriveType=3")
For each objDisk In Coldisks
'This script launches defrag and sends keys to the UI in order to automate the defrag
'process.
set WshShell = CreateObject("WScript.Shell")
'Launch Defrag from the command line and wait for a second
WshShell.Run "dfrg.msc"
WScript.Sleep 1000
'Wait until the application has loaded - Check every second
While WshShell.AppActivate("Disk Defragmenter") = FALSE
wscript.sleep 1000
Wend
'Bring the application to the foreground
WshShell.AppActivate "Disk Defragmenter"
WScript.Sleep 200
'Send an ALT-A key to bring down the defrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
'Sleep for 5 seconds
wscript.sleep 5000
'Send ALT-A key to bring down the defrag menu
WshShell.SendKeys "%A"
WScript.Sleep 500
'Send a s to stop the defrag
WshShell.SendKeys "D"
WScript.Sleep 3000
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
Next