Sign in to follow this  
Followers 0
prp2

How to make sure script ends if it doesn't completely run?

13 posts in this topic

Hello,

I'm new to AutoIT and I'm trying to build in a check to my scripts where if they don't fully complete, rather than just pause, then exit altogether.

This is probably an easy thing to do, but I'm having trouble figuring it out. Any thoughts? Thanks.

Share this post


Link to post
Share on other sites



Errr... how are we supposed to give ideas or help without your script? :lmao:


[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

Hello,

I'm new to AutoIT and I'm trying to build in a check to my scripts where if they don't fully complete, rather than just pause, then exit altogether.

This is probably an easy thing to do, but I'm having trouble figuring it out. Any thoughts? Thanks.

Post some code that you have and forum members might be better able to advise you. I'm going to guess that "timeouts" will be part of the answer/solution.

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ahh, sorry 'bout that. :lmao: This is the script (passwords edited out)...

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Peter Paulding II <xxxxxx>
;
; Script Function:
;   To enable FTP server in Zoom X5v router and upload GIS default config
;
; ----------------------------------------------------------------------------

; Script Start

$g_szVersion = "Zoom X5V Config"
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)

FileInstall ( "config.reg", "config.reg" )

; Log into Zoom using its default admin username/password and enable the built-in FTP server
Run ( 'explorer.exe "http://10.0.0.2/doc/misc.htm"' )
WinWaitActive ( "Connect to 10.0.0.2" )
Send ( "!u" )
Send ( "admin" )
Sleep ( 1000 )
Send ( "!p" )
Send ( "xxx" )
Sleep ( 1000 )
ControlClick ( "Connect to 10.0.0.2", "&Remember my password", "Button1" )
Send ( "{ENTER}" )
Sleep ( 5000 )
Send ( "^f" )
WinWaitActive ( "Find" )
Send ( "FTP" )
Send ( "{ENTER}" )
WinClose ( "Find" )
Send ( "{TAB}" )
Send ( "{DOWN}" )
Send ( "{TAB 11}" )
Send ( "{ENTER}" )
Sleep ( 3000 )
Send ( "^f" )
WinWaitActive ( "Find" )
Send ( "save" )
Send ( "{ENTER}" )
WinClose ( "Find" )
Send ( "{TAB}" )
Sleep ( 3000 )
Send ( "{ENTER}" )
Sleep ( 2000 )
Send ( "^f" )
WinWaitActive ( "Find" )
Send ( "process" )
Send ( "{ENTER}" )
WinClose ( "Find" )
Send ( "{TAB}" )
Sleep ( 3000 )
Send ( "{ENTER}" )
Sleep ( 30000 )

; After waiting for Zoom to reboot once change has been written to flash, FTP in via command prompt and upload GIS default config
Send ( "#r" )
WinWaitActive ( "Run" )
Send ( "cmd" )
Send ( "{ENTER}" )
Sleep ( 2000 )
Send ( "cd Desktop" )
Send ( "{ENTER}" )
Sleep ( 500 )
Send ( "ftp 10.0.0.2" )
Send ( "{ENTER}" )
Sleep ( 1000 )
Send ( "admin" )
Send ( "{ENTER}" )
Sleep ( 1000 )
Send ( "xxxxx" )
Send ( "{ENTER}" )
Sleep ( 1000 )
Send ( "put config.reg" )
Send ( "{ENTER}" )
Sleep ( 2000 )
Send ( "quit" )
Send ( "{ENTER}" )
Send ( "ipconfig /release" )
Send ( "{ENTER}" )
Sleep ( 500 )
Send ( "exit" )
Send ( "{ENTER}" )

; Popup window explaining remaining steps and cleaup other window
WinClose ( "http://10.0.0.2/doc/dosave.htm" )
FileDelete ( "config.reg" )
MsgBox ( 64, "Default Config Loaded", "The Zoom X5v has now been scripted with our default Galaxy configuration.  All you have left to do are:" & @CRLF & @CRLF & "1. Powercycle Zoom" & @CRLF & "2. Do an ipconfig /renew on your PC (maybe if it times out when grabbing one)" & @CRLF & "3. Login to 192.168.100.1 using the default Galaxy admin password" & @CRLF & "4. Input cx username/password and VoIP info in the appropriate fields per the sheet Mike P sent out" & @CRLF & "5. Save changes, write settings to flash and reboot, you're done!" )

; Script End

It's not very elegant, but it does the job I want so far. However, on some computers it doesn't always execute properly, and as such, you sometimes end up with 2 or 3 of the same script running after one has paused.

Edited by prp2

Share this post


Link to post
Share on other sites

You might want to hit the edit button on that last post and remove your e-mail address. (Assuming it is real, it could get harvested for spam.)


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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

use the timeout properties in conjunction with your winwaitactives and message box. Example:

Opt("WinTitleMatchMode",4); this is required because it allows you to use "active" to identify a window in the script...
WinWaitActive("Whatever","",10)
If WinGetTitle("active") <> "Whatever" Then Exit
Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

use the timeout properties in conjunction with your winwaitactives and message box. Example:

Opt("WinTitleMatchMode",4); this is required because it allows you to use "active" to identify a window in the script...
WinWaitActive("Whatever","",10)
If WinGetTitle("active") <> "Whatever" Then Exit

Ahh, thanks. I'll try that.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Untested, but try this...

If WinWaitActive ( "Connect to 10.0.0.2", 9) = 0 Then Exit

(change each of your WinWaitActive lines to something like the one above)

Edit1: Should be:

If WinWaitActive ( "Connect to 10.0.0.2", "window text", 9) = 0 Then Exit

@cameronsdad,

Care to remove his e-mail address from your quote of his edited post?

Edit2: Thanks cameronsdad for deleting the quote...

Edited by herewasplato

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

Share this post


Link to post
Share on other sites

Untested, but try this...

If WinWaitActive ( "Connect to 10.0.0.2", 9) = 0 Then Exit

(change each of your WinWaitActive lines to something like the one above)

Tried that one, and got an error, "Illegal text at the end of statement" Also I tried cameronsdad's example and had the scipt end immediately upon the first window becoming active, even though I had a 10-second timeout in there.

Share this post


Link to post
Share on other sites

@cameronsdad,

Care to remove his e-mail address from your quote of his edited post?

done, good catch. i didn't scrutinize the code very closely once i saw the issue/fix.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Tried that one, and got an error, "Illegal text at the end of statement" Also I tried cameronsdad's example and had the scipt end immediately upon the first window becoming active, even though I had a 10-second timeout in there.

there are a few things that could cause that with mine, 1 being that the window is a child window that returns the title of the parent to WinGetTitle("active"); or 2, you're not using the full window title in your comparison...check for either by adding this line before your new IF statement:

msgbox(0,"Title","Your window title is " & @lf & WinGetTitle("active"))
;or you could do this, then paste the title into your check:
ClipPut(WinGetTitle("active"))

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I failed to include the "window text" parameter:

If WinWaitActive ( "Connect to 10.0.0.2", "window text", 9) = 0 Then Exit

I should have been paying attention to the meeting that I was in instead of posting, but...

Here is a slightly cleaner version that I have tested...

If NOT WinWaitActive("Connect to 10.0.0.2", "", 3) Then MsgBox(0,"AutoIt","Timed Out")

Make a test script with just that one line of code in it and run it with and without the window present.

If it works for you, change the MsgBox to an Exit...

...or better yet send it to a UDF that cleans up after the failed script and then exits.

hope that I did not waste too much of your time with that lame reply of mine..............


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

Share this post


Link to post
Share on other sites

Thanks VERY much for your help, guys. It's nice to know that folks are willing to help out "newbies" so selflessly and quickly. Thanks again, this is becoming more fun the more I dig into it.

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