Sign in to follow this  
Followers 0
yoshald

defrag trouble - sched task pauses

8 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by MHz

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0