jwkh Posted October 1, 2006 Share Posted October 1, 2006 I'm trying to figure out how to automate the MS DF. I have a simple script using ScriptWriter, but I was wondering if using a program's drive pathing, telling it which buttons to select, etc.? TIA, jwkh Link to comment Share on other sites More sharing options...
creeping Posted October 1, 2006 Share Posted October 1, 2006 I'm trying to figure out how to automate the MS DF. I have a simple script using ScriptWriter, but I was wondering if using a program's drive pathing, telling it which buttons to select, etc.? TIA, jwkh Can you not just use #include <Process.au3> $drive = "c:" _RunDOS("defrag " & $drive) Link to comment Share on other sites More sharing options...
ChrisL Posted October 1, 2006 Share Posted October 1, 2006 I'm trying to figure out how to automate the MS DF. I have a simple script using ScriptWriter, but I was wondering if using a program's drive pathing, telling it which buttons to select, etc.? TIA, jwkh I've already done this, see how you get on with this. expandcollapse popup;error log events Global Const $SUCCESS = 0 Global Const $ERROR =1 Global Const $WARNING =2 Global Const $INFORMATION =4 Global Const $AUDIT_SUCCESS =8 Global Const $AUDIT_FAILURE =16 $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler for event log to prevent crash Defrag("C") Func Defrag($DrLeter) LogEvent ($INFORMATION, "Started a Defrag on Drive " & $DrLeter) If WinExists ("Disk Defragmenter") then Exit Run ("mmc Dfrg.msc " & $DrLeter & ":", @SystemDir) WinWait ("Disk Defragmenter") ControlClick ("Disk Defragmenter","","Defragment") WinWait ("Defragmentation Complete") ControlClick ("Defragmentation Complete","","Close") WinClose ("Disk Defragmenter") LogEvent ($SUCCESS, "DriveSpace Defrag Finished") EndFunc Func LogEvent($type,$text) $WshShell = ObjCreate("WScript.Shell") if not @error or $WshShell <> 0 Then $WshShell.LogEvent ($type,$text ) EndIf $WshShell = 0 EndFunc Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) SetError(1); something to check for when this function returns Endfunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
jwkh Posted October 1, 2006 Author Share Posted October 1, 2006 Can you not just use #include <Process.au3> $drive = "c:" _RunDOS("defrag " & $drive) I'd like to automate the process for N number of drives and use MS's task scheduler to kick it off. The include...I assume you need AutoIt installed on the system or the script compiled. (I haven't done any scripting (DOS batch files, etc.) in over 15 years. And saying I'm a Newbie to AutoIt is being very kind.) Thanks for your reply! jwkh Link to comment Share on other sites More sharing options...
jwkh Posted October 1, 2006 Author Share Posted October 1, 2006 I've already done this, see how you get on with this. expandcollapse popup;error log events Global Const $SUCCESS = 0 Global Const $ERROR =1 Global Const $WARNING =2 Global Const $INFORMATION =4 Global Const $AUDIT_SUCCESS =8 Global Const $AUDIT_FAILURE =16 $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler for event log to prevent crash Defrag("C") Func Defrag($DrLeter) LogEvent ($INFORMATION, "Started a Defrag on Drive " & $DrLeter) If WinExists ("Disk Defragmenter") then Exit Run ("mmc Dfrg.msc " & $DrLeter & ":", @SystemDir) WinWait ("Disk Defragmenter") ControlClick ("Disk Defragmenter","","Defragment") WinWait ("Defragmentation Complete") ControlClick ("Defragmentation Complete","","Close") WinClose ("Disk Defragmenter") LogEvent ($SUCCESS, "DriveSpace Defrag Finished") EndFunc Func LogEvent($type,$text) $WshShell = ObjCreate("WScript.Shell") if not @error or $WshShell <> 0 Then $WshShell.LogEvent ($type,$text ) EndIf $WshShell = 0 EndFunc Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) SetError(1); something to check for when this function returns Endfunc Thanks, This seems to be closer to what I'm looking for. Again, thanks! jwkh Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now