Jump to content

run program with error handling.


Go to solution Solved by 0xdefea7,

Recommended Posts

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}")

Link to comment
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.

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...