Sign in to follow this  
Followers 0
BartDog

run program with error handling.

8 posts in this topic

Greetings all!

Obviously I am new to this forum and even more obviously I am new to AutoIT.  But I am enjoying it and getting a lot of useful things out of it.  I have been using these forums since I started messing around with AutoIT for hints and things to research.  But I am now stuck on this one issue at the moment and was hoping someone could point me in the right direction or just point out what I am doing wrong with my scripts. 

This part of my script is pretty simple.  All I am having it do is launch a program and launch an update when the update window shows.  All that works fine but every once in a while it gets an error right after launching the program. At that point I am wanting it to clear the error (enter or click OK) and relaunch the program and start the update.  I have tried the following scripts but none seem to work. Any assistance would be appreciated. 

Run('C:CMProgram.exe')

If WinActivate("Error", "") Then
 Send("{ENTER}")
 Sleep(2000)
 Run('C:CMProgram.exe')
EndIf

_WinWaitActivate("Update Application", "")
Send("{ENTER}")

;=====================================================

Func CMerror()
 If _WinWaitActivate("Error", "&OK") Then
  MouseClick("left", 266, 11, 1)
  MouseClick("left", 286, 98, 1)
  Sleep(2000)
  Run('C:CMProgram.exe')
 EndIf
EndFunc   ;==>CMerror

AdlibRegister("CMerror")

Run('C:CMProgram.exe')

_WinWaitActivate("Update Application", "")
Send("{ENTER}")

AdlibUnRegister("CMerror")

;==================================================

Run('C:CMProgram.exe')

_WinWaitActivate("Error", "", 15)
Send("{ENTER}")
Sleep(2000)
Run('C:CMProgram.exe')

_WinWaitActivate("Update Application", "")
Send("{ENTER}")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try using the WinExists function to check for the error window. You should be able to just send enter after that. You may possibly have to TAB, then enter.

Also, you may find the info tool useful (Ctrl + F6 when using SciTE). 

http://www.autoitscript.com/autoit3/docs/intro/au3spy.htm

Edited by 0xdefea7
1 person likes this

Share this post


Link to post
Share on other sites

Thanks for the suggestion.  I have tried winexists (with the script below) and it did not work either.  I did put in the extra info from AU3Info which just the text "&OK" which I believe is not a requirement.  

 Run('C:CMProgram.exe')
 Sleep(5000)
 If WinExists("Error", "&OK") Then
  Send("{ENTER}")
  Sleep(2000)
  Run('C:CMProgram.exe')
 EndIf

 _WinWaitActivate("Update Application", "")
 Send("{ENTER}")

Any other ideas too look into would be appriciated.

Share this post


Link to post
Share on other sites

What about getting the Class info for the window and using it as the first argument in your WinExists:

WinExists("[Title:Error; Class:Program]", "")

Check this reference out for more ways to match the window title. Once you have that working, the rest will be easy. Using the au3info tool and this reference, you should be able to solve it :)

http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

1 person likes this

Share this post


Link to post
Share on other sites

I shall try out some of the Advanced Window Descriptions asap.  Though it may be a few more days before I can.  Thanks for the info.

Share this post


Link to post
Share on other sites

I finally got some machines up to do some testing and I believe I have finally got this working.  Thanks you very much for your assistance. 

Share this post


Link to post
Share on other sites

Please mark the topic as solved then, it is also nice to post your solution so that others can learn from it, not just you ;)

Share this post


Link to post
Share on other sites

You are so right. The solution was some of your suggestions and a few mistake corrections (Sequence error on my part).  Ended up with the following:

 

 If WinExists("Error", "&OK") Then
  WinActivate("Error", "&OK")
  Send("{Enter}")
  Sleep(2000)
  Run('C:CMProgram.exe')

 EndIf

Thanks Again.

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