this is what i found on the net, its a VB script which will kick off the defrag automatically. What i did was, create an AT cmd to run this program every other day and i'll use out the script using AD. But in order to run this program using this script you have to have admin rights, so my next question is, is there a way to put into the script to logon as an admin before running. the script is below:
'This script launches defrag and sends keys to the UI in order to automate the defrag
'process.
'This process requires the user to have administrative rights, and I'm still looking for
'a way to run this process in the background. If you schedule it to run via Scheduled
'Tasks, no user interface comes up and so the keystrokes don't get processed...
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 degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
wscript.sleep 1000
if WshShell.AppActivate("Defragmentation Complete") = TRUE then
' no way it's already defragged! must be a utility partition!
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send a DOWN key to arrow down to C: (hopefully)
WshShell.SendKeys "{DOWN}"
WScript.Sleep 200
'Send an ALT-A key to bring down the degrag menu
WshShell.SendKeys "%A"
WScript.Sleep 200
'Send a D to start the defrag
WshShell.SendKeys "D"
wscript.sleep 1000
end if
'Wait until the defrag is completed - Check for window every 5 seconds
While WshShell.AppActivate("Defragmentation Complete") = FALSE
wscript.sleep 5000
Wend
'Bring the msgbox to the foreground
WshShell.AppActivate "Defragmentation Complete"
WScript.Sleep 200
'Send a tab key to move the focus from View Report button to the Close Button
WshShell.Sendkeys "{TAB}"
Wscript.Sleep 500
'Send key to Close the Defragmentation Complete window
WshShell.Sendkeys "{ENTER}"
Wscript.Sleep 500
'Send and ALT-F4 to Close the Defrag program
WshShell.Sendkeys "%{F4}"
Josh McMahon
A+ Certified,CCNA
sold@joshmcmahon.com