yoshald Posted November 13, 2006 Share Posted November 13, 2006 I'm having some trouble with my first application of Autoit. I simply want defrag to run on a Win 2000 Pro machine weekly. I compiled the code below to an exe and set Windows Scheduled Tasks to run it weekly. Seems to work fine if I manually right-click the scheduled task and tell it to run. When unatended however it doesn't work. When I check on it after the task should be lanched, I don't see the deframent window, but I see the Autoit icon in the tray. Right-clicking it, it says task paused. Not sure what to do. Send("{LWINDOWN}") send("r") WinWaitActive("Run") send("{LWINUP}") Send("dfrg.msc e:") send("{ENTER}") WinWaitActive("Disk Defragmenter") Send("{TAB}") WinWaitActive("Disk Defragmenter") Send("{TAB}") WinWaitActive("Disk Defragmenter") Send("{TAB}") WinWaitActive("Disk Defragmenter") send("{SPACE}") P.S. Is there a way to close the Defragment window once it has completed? Link to comment Share on other sites More sharing options...
herewasplato Posted November 13, 2006 Share Posted November 13, 2006 (edited) I cannot remember if W2k has defrag.exe or not and if it does, the path may not be the same, but try something like this: Put the following into a text file and rename it something like Defrag-E.bat "C:\WINDOWS\system32\defrag.exe" e: -v pause Schedule that "bat" file for whenever you like. If you leave the "pause" line in, you will have evidence that it ran. If you want the window to close itself, remove the pause line. You can add as many lines as you would like: "C:\WINDOWS\system32\defrag.exe" c: -v "C:\WINDOWS\system32\defrag.exe" d: -v "C:\WINDOWS\system32\defrag.exe" e: -v pause Each line will run one after the other - in sequence. Edited November 13, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
MHz Posted November 13, 2006 Share Posted November 13, 2006 (edited) I cannot remember if W2k has defrag.exe or not and if it does, the path may not be the same, but try something like this:Win2k does not have a defrag.exe. Ezzetabi used to script a 3rd party defrag tool for this reason. Er, what is that systernals equivalent...and then search for that tool to defrag by script. Edited November 13, 2006 by MHz Link to comment Share on other sites More sharing options...
herewasplato Posted November 13, 2006 Share Posted November 13, 2006 (edited) Win2k does not have a defrag.exe...bummer@yoshald,I suppose that I should have mentioned that the WinWaitActive lines will not function if the workstation is locked or if the user is logged off... that is why I attempted to use the "bat"/defrag.exe method.Edit: check out this post:http://www.autoitscript.com/forum/index.php?showtopic=34211 Edited November 13, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
ChrisL Posted November 13, 2006 Share Posted November 13, 2006 Defrags C: and D: Defrag ("C") Defrag ("D") Func Defrag($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") 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...
lod3n Posted November 13, 2006 Share Posted November 13, 2006 WinWaitActive doesn't work when the screen is locked or from a scheduled task. The reason is that a window cannot become "active" in either of those two modes, presumably because the Ctrl-Alt-Delete window is actually the only active window. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
yoshald Posted November 20, 2006 Author Share Posted November 20, 2006 This looks like it will work for me. Thanks everyone. Defrags C: and D: Defrag ("C") Defrag ("D") Func Defrag($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") EndFunc Link to comment Share on other sites More sharing options...
lod3n Posted November 20, 2006 Share Posted November 20, 2006 Might want to throw a WinWaitClose in at the bottom if you're running them back to back like that. You half covered the issue with the WinExists at the top there though, so that's good. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] 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