Jump to content

Script doesn't work first time, but does after ran once.


Phexyaa
 Share

Recommended Posts

Hello,

I am writing a script that automates opening software, and clicking through config windows depending on my desired task. Ultimately this is part of a larger script that runs at windows startup and lets me use macros to automate my work p.c.

I am having trouble with the function below, in that it does not work the first time its ran. The strange thing to me is that it will work on the second, third, etc.

To be more specific the script runs, fails to do what it should and does not close itself like it should. So the second time I run the script, a paused script is in the background (I look in the notification area and see two icons one paused, and one for the current).

Its very strange to me that this script will only function if there is a paused / hung version of it in the background. This is repeatable by running the .exe or the script.

So here is the function that is giving me the issue:

 

Func newconfig()
   WinWait("6890 Provider 680 Administration Application")
   ControlCommand("6890 Provider 680 Administration Application","","ToolbarWindow321","SendCommandID",32783)
   WinWait("Configuration Choice Dialog") <-- this is where it seems to break down.
   ControlClick("Configuration Choice Dialog", "", 1370)
   Exit
EndFunc

I have tried using winwaitactive(), I have tried to add in msg boxes to display the returned handle from winwait() in an effort to try and debug, however on that first run they never appear, on the second run with a script in background the msg box does appear. Which leads me to believe it gets stuck at the winwait() call.

If someone can give me tips on how to debug winwait, winactive, etc more effectively I would greatly appreciate it. Or if there is a better solution that what I am trying please let me know

Edited by Phexyaa
Link to comment
Share on other sites

maybe something like this

Func newconfig()
    Do
        Local $sSuccess = False
        Local $hWnd1 = WinWait("6890 Provider 680 Administration Application", "", 10000)
        ControlCommand($hWnd1,"","ToolbarWindow321","SendCommandID",32783)
        
        Local $hWnd2 = WinWait("Configuration Choice Dialog", 10000)
        ControlClick($hWnd2, "", 1370)
    Until IsHWnd($hWnd1) & IsHWnd($hWnd2)
    Exit
EndFunc

This will wait the window for 10 seconds only, and if the window is not found, the script will run again

Edited by ngskicker
Link to comment
Share on other sites

Are you sure the title of the window your waiting for is correct? Try:

if not WinWait("Configuration Choice Dialog",50) then ;<-- this is where it seems to break down.
        ;error MsgBox
    else
        ;normal execution
    endif

May be you must change the TimeOut-param (50 second's) i used.

Set also:

("TrayIconDebug", 1) ;0=no info, 1=debug line info

in the beginning of your script to get the line where script hang's.

Edited by AutoBert
Link to comment
Share on other sites

 

Set also:

("TrayIconDebug", 1) ;0=no info, 1=debug line info

in the beginning of your script to get the line where script hang's.

Thanks  for the reply. I am sure that the title of the windows are correct, I used the autoit window tool to find the info.

Also the that debug line was very helpful. The tray icon is saying its at line 70 which is :

 

WinWait("6890 Provider 680 Administration Application")

But it has actually already executed line 71:

 

ControlCommand("6890 Provider 680 Administration Application","","ToolbarWindow321","SendCommandID",32783

Could this be related to the program's child parent relationship? when the config dialog pops up, it makes it so you cannot activate the main window ("Provider 680 admin..."), so could this be breaking the winwait?

 

Edited by Phexyaa
Link to comment
Share on other sites

Maybe a latency problem... you might try something like this

Func newconfig()
   $hWnd = WinWait("6890 Provider 680 Administration Application")
   Sleep(1000)
   WinActivate($hWnd)
   ControlCommand($hWnd,"","ToolbarWindow321","SendCommandID",32783)
   $hWnd2 = WinWait("Configuration Choice Dialog") 
   Sleep(1000)
   WinActivate($hWnd2)
   ControlClick($hWnd2, "", 1370)
   Exit
EndFunc

 

Link to comment
Share on other sites

Maybe a latency problem... you might try something like this

Func newconfig()
   $hWnd = WinWait("6890 Provider 680 Administration Application")
   Sleep(1000)
   WinActivate($hWnd)
   ControlCommand($hWnd,"","ToolbarWindow321","SendCommandID",32783)
   $hWnd2 = WinWait("Configuration Choice Dialog") 
   Sleep(1000)
   WinActivate($hWnd2)
   ControlClick($hWnd2, "", 1370)
   Exit
EndFunc

 

There was no change when I used this code. I have played around with delays before with no result.

If the WinWait line seems to be the problem I would be tempted to double check the window "title" and

AutoitSetOption settings for WinTitleMatchMode.

I have used the autoit window tool to gather window names etc, so I am pretty confident that they are correct.

 

I have downloaded and used a program called Autoit Debugger. Its new to me but from I can see I can step all the way up the line:

 

ControlCommand($hWnd,"","ToolbarWindow321","SendCommandID",32783)

but not beyond that. the winwait() calls function properly. If anyone is more familiar with this debugger maybe you can give me some tips to get some more useful information out of it. the control command line seems to return 0.

Also, I can close the dialog and re-open it manually and the script picks up from there and works, if that's useful to anyone.

Thanks,

George

Edited by Phexyaa
Link to comment
Share on other sites

OK so I got it to work in a round about way using a mouse click instead of control click.

 

Func newconfig()
   Local $hWnd = WinWait("6890 Provider 680 Administration Application")
   Sleep(15000)
   WinActivate($hWnd)
   ;ControlCommand($hWnd,"","ToolbarWindow321","SendCommandID",32783)
   MouseClick($MOUSE_CLICK_LEFT, 69, 80)
   ;MsgBox(0,"error",@error)
   $hWnd2 = WinWait("Configuration Choice Dialog")
   Sleep(1000)
   WinActivate($hWnd2)
   ControlClick($hWnd2, "", 1370)
   Exit

 

So it seems that it was hanging at the control command line.

I am happy that it works now, but I don't like using mouse click cords since the window might not always be in the same position.

so my questions are did I not use control command properly? I mean it opened the window like it should have but did not let the script continue afterwards.

Why would it work with a hung script in the background?

 

Thanks for the help thus far.

Edited by Phexyaa
Link to comment
Share on other sites

... but I don't like using mouse click cords since the window might not always be in the same position.

https://www.autoitscript.com/autoit3/docs/functions/WinGetPos.htm 
https://www.autoitscript.com/autoit3/docs/functions/WinGetClientSize.htm 
If ControlCommand don't work, you can find the position of the control. Not ideal, but, if it works.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/WinGetPos.htm 
https://www.autoitscript.com/autoit3/docs/functions/WinGetClientSize.htm 
If ControlCommand don't work, you can find the position of the control. Not ideal, but, if it works.

Thanks for your links. At this point I'm looking to find out why control command isnt working. I dont mind using a work around, but its a documented function that I would like to use. Maybe I should create a new post? but that seems a little unnecessary since its related to my original problem.

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...