Sign in to follow this  
Followers 0
doogdoog

Loop Question

11 posts in this topic

Aloha,

I am trying to write a script to start a defrag program, close popup, defrag c: hdd and d: hdd, and then close the program. So far the program starts, closes the popup, defrags the c: hdd but now I want it to continue with the d: hdd and then close the program. The first four lines of the script works ok but what do I add on line 5 & 9 to let the program run the defrag. until it is completed?. After the defrag is completed with C:, a popup comes up that I will close with line 6 and continue on to the D: drive but am stuck on what to add in line 5 & 6 so defrag will not just zip by. Do I use a loop? How do I stop the loop after the defrag is completed? TIA

; This script is to start Diskeeper and defrag the C & D Hdd and to close the program. 3-12-06 using Autoitv3.

; -------------------------------------------------------------------------

1) runwait (@comspec & " /c start dklite.msc")

2) Sleep (1000)

3) WinClose ("Diskeeper Lite")

4) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1)

5)

6) ControlClick ("Diskeeper Completed", "&OK",1,"",1) ;Closes Diskeeper Completed popup of C.

7) ControlClick ("Diskeeper Lite","",12785,"",1) ;Changes to D drive.

8) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1) ;Start Defrag on C.

9)

10) ControlClick ("Defragmentation Completed","OK",1,"",1) ;Closes Diskeeper Completed popup of D.

11) ControlClick ("Diskeeper Lite","",12785,"",1) ;Changes back to C to prepare new defrag in future.

12) WinClose ("Diskeeper Lite")

Mahalo,

doogdoog

Share this post


Link to post
Share on other sites



are you trying to say like on line 5 u want it to wait untill the defrag is done and then go onto pressing the OK button and stuff?

Share this post


Link to post
Share on other sites

AutoItSetOption("TrayIconDebug", 1) ;0-off
AutoItSetOption("WinDetectHiddenText", 1)

RunWait(@ComSpec & " /c start dklite.msc")

WinWait("Diskeeper Lite", "")
WinClose("Diskeeper Lite", "")

WinWait("Diskeeper Lite", "Defragment Now")
$check = ControlClick("Diskeeper Lite", "Defragment Now", 8101)
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

WinWait("Diskeeper Lite", "&OK")
$check = ControlClick("Diskeeper Completed", "&OK", 1);Closes Diskeeper Completed popup of C.
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

$check = ControlClick("Diskeeper Lite", "", 12785);Changes to D drive.
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

WinWait("Diskeeper Lite", "Defragment Now")
$check = ControlClick("Diskeeper Lite", "Defragment Now", 8101);Start Defrag on C.
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

WinWait("Diskeeper Lite", "OK")
$check = ControlClick("Defragmentation Completed", "OK", 1);Closes Diskeeper Completed popup of D.
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

$check = ControlClick("Diskeeper Lite", "", 12785);Changes back to C to prepare new defrag in future.
If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

WinWait("Diskeeper Lite", "")
WinClose("Diskeeper Lite", "")


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

Share this post


Link to post
Share on other sites

Aloha,

Thanks for the replies and the help Neogia, thatsgreat2345 and herewasplato. I finally got it to work after hours of trial and error and herewasplato thanks for the posting, but I don't understand your script (too deep for me). I will have to do some search on your scripts to figure out what it does. TIA

Mahalo,

doogdoog

; Script Function:

; Template AutoIt script.

; This script is to start Diskeeper and defrag the C & D Hdd and to close the program. Created by doogdoog 3-12-06 using Autoitv3.

; -------------------------------------------------------------------------

1) RunWait (@comspec & " /c start dklite.msc") ;Starts Diskeeper program.

2) Sleep (1000)

3) WinClose ("Diskeeper Lite") ;Closes popup.

4) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1) ;Starts to defrag hdd.

5) WinWait("Defragmentation Completed", "&OK") ;Waits until defrag of C is completed.

6) WinClose ("Defragmentation Completed") ;Closes Diskeeper Completed popup of C.

7) MouseClick ("",90,98,1) ;Changes to D drive.

8) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1) ;Start Defrag on D.

9) WinWait("Defragmentation Completed", "&OK") ;Waits until defrag of D is completed.

10) WinClose ("Defragmentation Completed");Closes Diskeeper Completed popup of D.

11) MouseClick ("",80,80,1) ;Changes back to C to prepare new defrag in future.

12) WinClose ("Diskeeper Lite") ;Exit program.

Share this post


Link to post
Share on other sites

Aloha,

Thanks for the replies and the help Neogia, thatsgreat2345 and herewasplato. I finally got it to work after hours of trial and error and herewasplato thanks for the posting, but I don't understand your script (too deep for me). I will have to do some search on your scripts to figure out what it does. TIA

Mahalo,

doogdoog

; Script Function:

; Template AutoIt script.

; This script is to start Diskeeper and defrag the C & D Hdd and to close the program. Created by doogdoog 3-12-06 using Autoitv3.

; -------------------------------------------------------------------------

1) RunWait (@comspec & " /c start dklite.msc") ;Starts Diskeeper program.

2) Sleep (1000)

3) WinClose ("Diskeeper Lite") ;Closes popup.

4) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1) ;Starts to defrag hdd.

5) WinWait("Defragmentation Completed", "&OK") ;Waits until defrag of C is completed.

6) WinClose ("Defragmentation Completed") ;Closes Diskeeper Completed popup of C.

7) MouseClick ("",90,98,1) ;Changes to D drive.

8) ControlClick ("Diskeeper Lite","Defragment Now",8101,"",1) ;Start Defrag on D.

9) WinWait("Defragmentation Completed", "&OK") ;Waits until defrag of D is completed.

10) WinClose ("Defragmentation Completed");Closes Diskeeper Completed popup of D.

11) MouseClick ("",80,80,1) ;Changes back to C to prepare new defrag in future.

12) WinClose ("Diskeeper Lite") ;Exit program.

What parts don't you understand? I'm sure one of us can explain it to where you could maybe get a grasp of it, since you'll probably need it for future reference anyway.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

AutoItSetOption("TrayIconDebug", 1);0-off

Set so that tray displays current line number

AutoItSetOption("WinDetectHiddenText", 1)

Allow Autoit to detect the hidden text on the windiw

RunWait(@ComSpec & " /c start dklite.msc")

Run the program dklite.msc

WinWait("Diskeeper Lite", "")

Wait for a window with the title "Diskeeper Lite"

WinClose("Diskeeper Lite", "")

Close the window with the title "Diskeeper Lite"

WinWait("Diskeeper Lite", "Defragment Now")

Wait for a window with the title "Diskeeper Lite", text "Defragment Now"

$check = ControlClick("Diskeeper Lite", "Defragment Now", 8101)

Click Control #8101 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

WinWait("Diskeeper Lite", "&OK")

Wait for a window with the title "Diskeeper Lite", text "&OK"

$check = ControlClick("Diskeeper Completed", "&OK", 1);Closes Diskeeper Completed popup of C.

Click Control #1 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

$check = ControlClick("Diskeeper Lite", "", 12785);Changes to D drive.

Click Control #12785 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

WinWait("Diskeeper Lite", "Defragment Now")

Wait for a window with the title "Diskeeper Lite", text "Defragment Now"

$check = ControlClick("Diskeeper Lite", "Defragment Now", 8101);Start Defrag on C.

Click Control #8101 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

WinWait("Diskeeper Lite", "OK")

Wait for a window with the title "Diskeeper Lite", text "OK"

$check = ControlClick("Defragmentation Completed", "OK", 1);Closes Diskeeper Completed popup of D.

Click Control #1 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

$check = ControlClick("Diskeeper Lite", "", 12785);Changes back to C to prepare new defrag in future.

Click Control #12785 on the window

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

If control not found, display a message box, alerting the user.

WinWait("Diskeeper Lite", "")

Wait for a window with the title "Diskeeper Lite"

WinClose("Diskeeper Lite", "")

Closes the window with the title "Diskeeper Lite"

Step-by-step walkthrough

#)

Share this post


Link to post
Share on other sites

Err... nfwu could break it down entirley~~!! :)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Aloha,

Thanks for the breakdown. Well, I didn't quite understand $check, if $check, and msgbox. I looked at the help but couldn't find check but I found that $ is a variable. I also couldn't understand why msgbox would be part of the program but now I am thinking that those additional scripts are there to show if there is a problem. Is that correct?? Ok, I got it and thanks to you all again. TIA

Mahalo,

doogdoog

Share this post


Link to post
Share on other sites

Aloha,

Thanks for the breakdown. Well, I didn't quite understand $check, if $check, and msgbox. I looked at the help but couldn't find check but I found that $ is a variable. I also couldn't understand why msgbox would be part of the program but now I am thinking that those additional scripts are there to show if there is a problem. Is that correct?? Ok, I got it and thanks to you all again. TIA

Mahalo,

doogdoog

@nfwu,

Thanks - I've not had time to stay on the forum much as of late.

@doogdoog,

Yes, in this case - msgbox = debug/problem - once the script is working, then you should not see them popup... however, ControlIDs have been known to change within a program from one run to the next or if there is a patch/upgrade... so you might want to keep them in there.

Check the help file under ControlClick and you should see this:

Return Value

Success: Returns 1.

Failure: Returns 0.

When you execute a line of code containing a ControlClick function it will return (or send) a 1 or a 0 to a variable or another function. $check is just the name of the variable that I picked. I could have named the variable $x or $y like in algebra - but who wants to go there?

One of the things that I noticed about your code was that you were not putting any WinWaits in it. While I was messing around with writing out the whole script - nfwu posted the same idea... that is why I just posted my whole version and left it at that. I probably should not have thrown the msgboxes into the equation, but some of your control IDs looked like they might have been in error.

Another way to write this line:

If $check = 0 Then MsgBox(0, "AutoIt", "Control Not found.")

is

If Not $check Then MsgBox(0, "AutoIt", "Control Not found.")

I throw that in because I know that lines of code like (If $check = 0 Then...) really offends some coders' senses... but I think that it is clearer for those just starting out. I know that it was for me.

What happens when you run the code that I posted? - if you are that brave :-)


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

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