Jump to content

Newbee to AutoIt


 Share

Recommended Posts

6 hours ago, jdelaney said:

The window opens, but you are waiting on the parent window to return success.   which won't happen until the popup is closed.   in the helpfile, search command line variables for examples of running a line of script as a second process.

 

You can verify this by putting a msgbox right after the control command call.  the msgbox won't come up until you close the window.   then your script waits 10 seconds while failing to find the already closed window.

jdelaney, try as i might i can't find anything that talks about multiple process.  I've tried this forum, the wiki, the functions and UDFs. Can you point me to something that may shed some light on this subject.

Link to comment
Share on other sites

Open scite, press f1 key, search command line parameter.  I'm away from my computer, so that's the best I can do for you.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

On 2/6/2018 at 3:05 PM, TheWizEd said:

Success.  But it seems this is trial and error try ControlClick, try WinMenuSelectItem, try Send.

@TheWizEd

Welcome to AutoIT.   Like most programming languages, AutoIT has more than one way to solve a problem.  AutoIT is pretty flexible and it's hard sometimes to figure out exactly what function to use since there can be several that might get you to where you want to go.  Naturally some functions and ideas are better than others. 

But, it's also hard to tell which one until you play with the code a bit. 

When I do anything related controlling an external app I write lots of code to check for errors.  That's a bit vague but I took your code and modified it a bit to give you a general idea of what I mean.    Since I don't have your downloader app and have't tested it, treat this more like pseudocode than real code .

; Script Start - Add your code below here
#include <MsgBoxConstants.au3>

Local $pId = Run("C:\Program Files (x86)\Equis\The DownLoader\Dlwin.exe")
If @error = 0 ; Run returned an error
    MsgBox(0,"Error","PID Missing. The Downloader did not load.")
EndIf

MsgBox(0,"What's my PID?","PID = " & $pID)

Sleep(4000)  ; Wait for splash screen <--- Your next line contains a 10 second wait.  This probably isn't needed.

Local $hWnd = WinWaitActive("The DownLoader", "", 10); <--- you have a 10 second delay here.  
If @error = 0 Then  ; Timed out. Otherwise a handle is returned.
    MsgBox(0,"Error","The Downloader timed out after 10 seconds.")
EndIf

MsgBox(0, "hWnd", "Window Handle for The Downloader = " & $hWnd)

If Not WinExists("The Downloader") Then
    ; Figure out what to do next.  Terminate or ?
EndIf
;~ Sleep(5000); ADDED LINE TO PAUSE SCRIPT 5 SECONDS

WinActivate($hWnd)

; Assuming everything worked, your "The Downloader" screen is active.
ControlFocus($hWnd,"","[ID:57601]") ; Try to get the focus on the ControlID you identified. 
If @error = 0 Then ; failed to get focus.
    MsgBox(0,"Error", "Could not find Control: 57601")
EndIf
; Since there wasn't an error then...
ControlClick($hWnd,"","[ID:57601]")

Just a suggestion. Otherwise it get's pretty difficult to track down where the problem is.   Once you track down the problem and the code is solid then you can always strip out the unnecessary stuff.   Also, assuming you're using Scite, you will want to use some of the "debug" options under Tools.  My most used is putting cursor over a variable and pressing Ctrl+D.  That will cause Scite to write the line number, variable name, and the variable value, as well as an @error code into the Console when you run the program in Scite (not executable).  Putting the cursor over a keyword and pressing F1 will jump you to help. I pretty much live with Scite and Help running at the same time.  I've been working AutoIt since 2006 and being older and admitting that my memory works less like a recorder and more like a sieve I rely on the help system.

Good Luck

Link to comment
Share on other sites

@OldGuyWalking, the problem is known, he needed the execution to correct it.

Back at my computer:

Run('"' & @AutoItExe & '" /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand ( hwnd(' & $hCallersWindow & '),'''', hwnd(' & $hCallersToolbar & '), ''SendCommandID'', ' & $iCallersCommandID & ' )"')

Substitute in your handles, and the above, new process will be deadlocked, so that your script may continue.

Link to the helpfile for command line parameters:

https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

5 minutes ago, jdelaney said:

@OldGuyWalking, the problem is known, he needed the execution to correct it.

Back at my computer:

Run('"' & @AutoItExe & '" /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand ( hwnd(' & $hCallersWindow & '),'''', hwnd(' & $hCallersToolbar & '), ''SendCommandID'', ' & $iCallersCommandID & ' )"')

Substitute in your handles, and the above will be deadlocked, so that your script may continue.

Link to the helpfile for command line parameters:

https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine

@jdelaney Apologies, I wasn't trying to step on your toes or get in your way.  My intention was to provide a bit of information to the OP about something the OP seemed not to be including in their code and that was capturing errors and debugging options.  Might not be helpful for this particular problem but might be useful for the next one.

 

Link to comment
Share on other sites

@OldGuyWalking & @jdelaney  first I'm not using Scite, I use Notepad++ for everything I do.  second, if using ControlCommand is so complicated there should be more examples to document how its used.  Searching the wiki and forum doesn't turn up much.

I was finally able to automate my task using a series of keystroke. Send(...)s to achieve my objective.  A bunch of {ALT}s.  But wanted to figure out how to use the applications toolbar.  That's when I got in trouble.

OldGuy, yes, I developed my own utility to monitor incremental progress because I was't aware of the _Debug UDFs.

Both of you thanks for your help.

Link to comment
Share on other sites

Get ready to be disappointed with consistency. Use scite, it had intelisense, much easier to debug also.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Did you update the run to use your data?   post what you changed.   if you aren't using handles and you left in the hwnd (), it will fail.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

3 hours ago, jdelaney said:

Did you update the run to use your data?   post what you changed.   if you aren't using handles and you left in the hwnd (), it will fail.

So I tried several different way but nothing seems to work.  _CheckStatus just checks @error and return value from function call as well as time to execute command.

#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Array.au3>
#include "UtilLibrary.au3"

Local $iStartTime = _Timer_Init()
Local $pId = Run("C:\Program Files (x86)\Equis\The DownLoader\Dlwin.exe") ; $pId is a handle value
_CheckStatus("Run","$pId",$pId,@error,@extended,$iStartTime)

$iStartTime = _Timer_Init()
Local $hWnd = WinWaitActive("The DownLoader","",10) ; $hWnd is a handle value
_CheckStatus("WinWaitActive","$hWnd",$hWnd,@error,@extended,$iStartTime)

$iStartTime = _Timer_Init()
Local $hControl = ControlGetHandle($hWnd,"",59394) ; $hControl is a handle value
_CheckStatus("ControlGetHandle","$hControl",$hControl,@error,@extended,$iStartTime)

; Open file from toolbar
$iStartTime = _Timer_Init()
Local $sCommand = @AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand( hwnd(' & $hWnd & '),'''', hwnd(' & $hControl & '),''SendComandID'',57601)"'
;Local $sCommand = @AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand( hwnd(' & $hWnd & '),'''',59394,''SendComandID'',57601)"'
;Local $sCommand = @AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand( hwnd(' & $hWnd & '),'''',''[ID:59394]'',''SendComandID'',57601)"'
MsgBox($MB_SYSTEMMODAL, "",$sCommand)

Local $vResult = Run($sCommand)
_CheckStatus("Run","$vResult",$vResult,@error,@extended) ; $vResult is an integer number
 

 

Link to comment
Share on other sites

You removed some quotes that were intentionally there to account for white spaces within the path to the autoit exe...added them back in:

Local $sCommand = '"' & @AutoItExe & '" /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand( hwnd(' & $hWnd & '),'''', hwnd(' & $hControl & '),''SendComandID'',57601)"'

Does _CheckStatus wait for a return?  If it does, remove it.  You should just be waiting for the window once you send the command, because the command, when ran successfully, will not return until your script (or you) closes the window that popsup.

Edit: looks like that's just a logger/debugger, yes?  Then it's fine to leave it in.  Did the output show you were grabbing the proper handles for the window and control?

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

@jdelaney Nope still no display.  Command cut from here and pasted into my script.

Local $sCommand = '"' & @AutoItExe & '" /ErrorStdOut /AutoIt3ExecuteLine "ControlCommand( hwnd(' & $hWnd & '),'''', hwnd(' & $hControl & '),''SendComandID'',57601)"'

From _CheckStatus, creates a log

Success in Run varvame = $pId result = 12164 elapsed time = 6
Success in WinWaitActive varvame = $hWnd result = 0x000405AA elapsed time = 265
Success in ControlGetHandle varvame = $hControl result = 0x000405E8 elapsed time = 1
Success in Run varvame = $vResult result = 13036
 

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