Jump to content

Script works ... some of the time.


Recommended Posts

So I made this script to start a program.  It works some of the time.  How can I increase the chance that it will complete it's work properly?

it seems to be getting stuck the most at Line45.  I was thinking about maybe putting an if statement there.  When it doesn't work properly it just opens the window and gets stuck there.

Any pointers would be nice.  I am relatively new to using AutoIT.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=c:\scripts\LKBL-Start.exe
#AutoIt3Wrapper_Outfile_x64=c:\scripts\LKBL-Start_x64.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AutoItConstants.au3>
#include <ScreenCapture.au3>
LeadKingStart()

Func LeadKingStart()
    MouseMove(165,342,0)
    MouseMove(165,342,0)
    Sleep(15000);wait for system to wake up
    Send("#d")
    ;Block Keyboard/Mouse Input
    BlockInput($BI_DISABLE)
    ; Run LeadKing
    Run("C:\Users\Administrator\Desktop\Lead King Phone Broadcast\BroadcastLite.exe")

    ; Wait 10 seconds for the LeadKing error window to appear.
    ;Local $hWnd1 = WinWait("[TITLE:Lead King Software]","", 30)
    ;Click OK on the error window
    ;ControlClick($hWnd1, "", "[ID:2]")

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Wait 30 seconds for the LeadKing window to appear.
    Local $hWnd = WinWait("[TITLE:Lead King Broadcast Lite Vx2.2]", "", 30)
    ;Loop through to fix bug where file doesn't open correctly.
    ;WinMove($hWnd,"",0,0)
    Local $i = 0;
    While $i <=1;
    ; Send a mouse click to LeadKing open Control to select VOIP Settings
    ControlClick($hWnd, "", "[NAME:btn_OpenVOIPSettings]")

    Local $hWndOpen = WinWait("[TITLE:Open]","",30)

    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Send filename to VOIP Settings
        sleep(200)
    ControlSetText($hWndOpen, "", 1148, "C:\Users\Administrator\Desktop\Lead King Phone Broadcast\enqwestvoip.txt")
    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Open the Voip Settings File
    ControlClick($hWndOpen, "", "[CLASS:Button; INSTANCE:1]")
    ; Wait for 2 seconds.
    ;Sleep(2000)
    $i = $i + 1
    WEnd;end loop open voip settings.
    Sleep(15000)
    ;Click Start button to begin calling
    ;MouseMove(165,342,0)
    ;MouseClick("left", 165, 342,1,0)
    ;Sleep(4000)
    ;WinClose($hWnd)
    ;Send("n")
    ;Enable Input
    ControlClick("Lead King Broadcast Lite Vx2.2", "", "[NAME:cb_AutoProcess]")
    BlockInput($BI_ENABLE)
EndFunc   ;==>LeadKingStart

;Create name of file
$sFileName ="C:\scripts\screenshot.jpg"

;Capture Screen save to file in variable $Name
_ScreenCapture_Capture($sFileName)

Marcus

 

Edited by marcusawerly
Link to comment
Share on other sites

Since we cannot run your script, I would suggest you insert multiple ConsoleWrite to check for @error and return value of the functions you use.  Post here the console result when it gets stuck.

By using ConsoleWrite, It will also help you to follow the path of your script.

ps. when posting code, use this tool.

Link to comment
Share on other sites

please post code using the code tags. they look like this when you make a post, <>

downloading is annoying.

looks like this might be a waiting issue. canned--non dynamic waiting will do this stuff. I wrote a udf that waits for controls forever, unless you define a timeout.

as mentioned above, logging is your friend. do it to debug

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Here an example with your code (now complete with the rest of the script) :

Local $Test = ControlClick($hWnd, "", "[NAME:btn_OpenVOIPSettings]")
ConsoleWrite ("After control click " & $Test & "/" & @error & @CRLF)
Local $hWndOpen = WinWait("[TITLE:Open]","",30)
ConsoleWrite ("After WinWait " & $hWndOpen & "/" & @error & @CRLF)
sleep(200)
$Test = ControlSetText($hWndOpen, "", 1148, "C:\Users\Administrator\Desktop\Lead King Phone Broadcast\enqwestvoip.txt")
ConsoleWrite ("After control set text " & $Test & "/" & @error & @CRLF)

You run it from Scite...

Edited by Nine
Link to comment
Share on other sites

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=c:\scripts\LKBL-Start.exe
#AutoIt3Wrapper_Outfile_x64=c:\scripts\LKBL-Start_x64.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AutoItConstants.au3>
#include <ScreenCapture.au3>
LeadKingStart()

Func LeadKingStart()
    MouseMove(165,342,0)
    MouseMove(165,342,0)
    Sleep(15000);wait for system to wake up
    Send("#d")
    ;Block Keyboard/Mouse Input
    BlockInput($BI_DISABLE)
    ; Run LeadKing
    Run("C:\Users\Administrator\Desktop\Lead King Phone Broadcast\BroadcastLite.exe")

    ; Wait 10 seconds for the LeadKing error window to appear.
    ;Local $hWnd1 = WinWait("[TITLE:Lead King Software]","", 30)
    ;Click OK on the error window
    ;ControlClick($hWnd1, "", "[ID:2]")

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Wait 30 seconds for the LeadKing window to appear.
    Local $hWnd = WinWait("[TITLE:Lead King Broadcast Lite Vx2.2]", "", 30)
    ;Loop through to fix bug where file doesn't open correctly.
    ;WinMove($hWnd,"",0,0)
    Local $i = 0;
    While $i <=1;
    ; Send a mouse click to LeadKing open Control to select VOIP Settings
    Local $Test = ControlClick($hWnd, "", "[NAME:btn_OpenVOIPSettings]")
    ConsoleWrite ("After L37:control click " & $Test & "/" & @error & @CRLF)
    Local $hWndOpen = WinWait("[TITLE:Open]","",30)
    ConsoleWrite ("After L39:WinWait open " & $hWndOpen & "/" & @error & @CRLF)
    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Send filename to VOIP Settings
        sleep(200)
    Local $Test = ControlSetText($hWndOpen, "", 1148, "C:\Users\Administrator\Desktop\Lead King Phone Broadcast\enqwestvoip.txt")
    ConsoleWrite("After L46:ControlSetText " & $Test & "/" & @error & @CRLF)
    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Open the Voip Settings File
    Local $Test = ControlClick($hWndOpen, "", "[CLASS:Button; INSTANCE:1]")
    ConsoleWrite("After L50:ControlClick " & $Test &  "/" & @error & @CRLF)
    ; Wait for 2 seconds.
    ;Sleep(2000)
    $i = $i + 1
    WEnd;end loop open voip settings.
    Sleep(15000)
    ;Click Start button to begin calling
    ;MouseMove(165,342,0)
    ;MouseClick("left", 165, 342,1,0)
    ;Sleep(4000)
    ;WinClose($hWnd)
    ;Send("n")
    ;Enable Input
    Local $Test = ControlClick("Lead King Broadcast Lite Vx2.2", "", "[NAME:cb_AutoProcess]")
    ConsoleWrite("After L64:ControlClick " & $Test & "/" & @error & @CRLF)
    BlockInput($BI_ENABLE)
EndFunc   ;==>LeadKingStart

;Create name of file
$sFileName ="C:\scripts\screenshot.jpg"

;Capture Screen save to file in variable $Name
_ScreenCapture_Capture($sFileName)


LOG_---------------------------------------------------------------------------------------------------------------------------------------

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Documents\LKBL-Startv1.au3" /UserParams    
+>12:21:33 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000409  OS:WIN_2016/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Administrator\Documents\LKBL-Startv1.au3
+>12:21:33 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Administrator\Documents\LKBL-Startv1.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
After L37:control click 1/0
After L39:WinWait open 0x0000000000310428/0
After L46:ControlSetText 1/0
After L50:ControlClick 1/0
After L37:control click 1/0
After L39:WinWait open 0x0000000000320428/0
After L46:ControlSetText 1/0
After L50:ControlClick 1/0
After L64:ControlClick 1/0
+>12:22:08 AutoIt3.exe ended.rc:0
+>12:22:08 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 35.49

Log is at the bottom.  It looks like a log from a good run but it failed "After L50:ControlClick"  the window stayed open.  There is no way it actually did After L64: because the window wasn't active.  The Open Dialogue Box was still open from inside the while loop.

Marcus

Link to comment
Share on other sites

Better use :

ConsoleWrite ("After L" & @ScriptLineNumber & ":control click ... " & @CRLF)

instead of  :

ConsoleWrite ("After L37:control click " & $Test & "/" & @error & @CRLF)

The line numbers will now change automatically, if you alter the script (for example insert new lines).

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=c:\scripts\LKBL-Start.exe
#AutoIt3Wrapper_Outfile_x64=c:\scripts\LKBL-Start_x64.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AutoItConstants.au3>
#include <ScreenCapture.au3>
LeadKingStart()

Func LeadKingStart()
    MouseMove(165,342,0)
    MouseMove(165,342,0)
    Sleep(15000);wait for system to wake up
    Send("#d")
    ;Block Keyboard/Mouse Input
    BlockInput($BI_DISABLE)
    ; Run LeadKing
    Run("C:\Users\Administrator\Desktop\Lead King Phone Broadcast\BroadcastLite.exe")

    ; Wait 10 seconds for the LeadKing error window to appear.
    ;Local $hWnd1 = WinWait("[TITLE:Lead King Software]","", 30)
    ;Click OK on the error window
    ;ControlClick($hWnd1, "", "[ID:2]")

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Wait 30 seconds for the LeadKing window to appear.
    Local $hWnd = WinWait("[TITLE:Lead King Broadcast Lite Vx2.2]", "", 30)
    ;Loop through to fix bug where file doesn't open correctly.
    ;WinMove($hWnd,"",0,0)
    Local $i = 0;
    While $i <=1;
    ; Send a mouse click to LeadKing open Control to select VOIP Settings
    Local $Test = ControlClick($hWnd, "", "[NAME:btn_OpenVOIPSettings]")
    ConsoleWrite ("After L37:control click " & $Test & "/" & @error & @CRLF)
    Local $hWndOpen = WinWait("[TITLE:Open]","",30)
    ConsoleWrite ("After L39:WinWait open " & $hWndOpen & "/" & @error & @CRLF)
    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Send filename to VOIP Settings
        sleep(200)
    Local $Test = ControlSetText($hWndOpen, "", 1148, "C:\Users\Administrator\Desktop\Lead King Phone Broadcast\enqwestvoip.txt")
    ConsoleWrite("After L46:ControlSetText " & $Test & "/" & @error & @CRLF)
    ;Wait for 2 seconds.
    ;Sleep(2000)
    ; Open the Voip Settings File
    Local $Test = ControlClick($hWndOpen, "", "[CLASS:Button; INSTANCE:1]")
    ConsoleWrite("After L50:ControlClick " & $Test &  "/" & @error & @CRLF)
    ; Wait for 2 seconds.
    ;Sleep(2000)
    $i = $i + 1
    WEnd;end loop open voip settings.
    Sleep(15000)
    ;Click Start button to begin calling
    ;MouseMove(165,342,0)
    ;MouseClick("left", 165, 342,1,0)
    ;Sleep(4000)
    ;WinClose($hWnd)
    ;Send("n")
    ;Enable Input
    Local $Test = ControlClick("Lead King Broadcast Lite Vx2.2", "", "[NAME:cb_AutoProcess]")
    ConsoleWrite("After L64:ControlClick " & $Test & "/" & @error & @CRLF)
    BlockInput($BI_ENABLE)
EndFunc   ;==>LeadKingStart

;Create name of file
$sFileName ="C:\scripts\screenshot.jpg"

;Capture Screen save to file in variable $Name
_ScreenCapture_Capture($sFileName)

After L37:control click 0/0
After L39:WinWait open 0/0
After L46:ControlSetText 0/0
After L50:ControlClick 0/0
After L64:ControlClick 1/0>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Documents\LKBL-Startv1.au3" /UserParams    
+>12:39:27 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000409  OS:WIN_2016/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Administrator\Documents\LKBL-Startv1.au3
+>12:39:28 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Administrator\Documents\LKBL-Startv1.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
After L37:control click 0/0
After L39:WinWait open 0/0
After L46:ControlSetText 0/0
After L50:ControlClick 0/0
After L64:ControlClick 1/0
+>12:40:17 AutoIt3.exe ended.rc:0
+>12:40:17 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 49.89

+>12:40:17 AutoIt3.exe ended.rc:0
+>12:40:17 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 49.89

I removed the while loop.  What does the 0/0 vs 1/0 mean?

Link to comment
Share on other sites

2 hours ago, marcusawerly said:

What does the 0/0 vs 1/0 mean?

If you read help file, It means failure when result is 0 in the case of controlclick  and WinWait. Please refer to help file for all the value of result and @error if set.

Link to comment
Share on other sites

Not all functions set @error, it is just a generic way to make sure you got all the informations to debug correctly. If a function doesn't set @error then it will normally be set to 0.

Please do not post on oversize bold font, it feels agressive.  Remember that we all do help on our free time...

Edited by Nine
Link to comment
Share on other sites

On 9/19/2019 at 9:55 AM, Earthshine said:

please post code using the code tags. they look like this when you make a post, <>

downloading is annoying.

looks like this might be a waiting issue. canned--non dynamic waiting will do this stuff. I wrote a udf that waits for controls forever, unless you define a timeout.

as mentioned above, logging is your friend. do it to debug

is it on this forum?  I think that is what I will likely need.  It isn't waiting properly.

Marcus

Link to comment
Share on other sites

yeah. but here it is again...

#include-once
#include <Timers.au3>
#include "log4a.au3"

; #FUNCTION# ====================================================================================================================
; Name ..........: _checkClickCtrl
; Description ...: Automatically wait for a control to exist. Forever or Limited
; Syntax ........: _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout, $delayafter
; Parameters ....: $formclass           - Form Class info.
;                  $text                - Windows text to match
;                  $ctrl                - Class of Copntrol
;                  $ctrltxt             - Text of the Control
;                  $timeout             - Timeout = 0 by default, millisecond timer
;                  $delayafter          - Time in milliseconds to delay after operation carried out
; Return values .: None
; Author ........: Earthshine
; Modified ......:
; Remarks .......:  Waits for each button indefinatly, unless you give it a timeout
;                   Logger found here: https://www.autoitscript.com/forum/topic/156196-log4a-a-logging-udf/
; Related .......:
; Link ..........:
; Example(s) ....:  _checkClickCtrl ('[CLASS:#32770]', 'ApplicationX - InstallShield Wizard', '[CLASS:Button; INSTANCE:1]', , '&Next >' 5000, 0)
;                   _checkClickCtrl($formclass, $text, $button2, $TD_BTN_REMOVE, 0, 0)
;                   _checkClickCtrl($formclass, $text, $button3, $TD_BTN_NEXT, 0, 500)
;                   _checkClickCtrl($formclass, $text, $button1, $TD_BTN_YES, 0, 0)
;                   _checkClickCtrl($formclass, $text, $button4, $TD_BTN_FINISH, 0, 0)
; ===============================================================================================================================
Func _checkClickCtrl($formclass, $text, $ctrl, $ctrltxt, $timeout = 0, $delayafter = 0)
    _log4a_Info("_checkClickCtrl():Begin")
    _log4a_Info("Searching for Formclass: " & $formclass)
    _log4a_Info("Searching for Text: " & $text)
    _log4a_Info("Searching for Control: " & $ctrl)
    _log4a_Info("Searching for Ctrl Txt: " & $ctrltxt)
    _log4a_Info("Timeout: " & $timeout)
    _log4a_Info("Time Delay (after click): " & $delayafter)
    Local $time_run = _Timer_Init()
    While (1)
        If WinExists($formclass) Then
            Local $hCtrl = ControlGetHandle($text, '', $ctrl)
            If $hCtrl Then
                If ($timeout > 0) Then
                    _log4a_Info(_Timer_Diff($time_run))
                    If (_Timer_Diff($time_run) > $timeout) Then
                        _log4a_Info("ExitLoop:Timeout - " & $ctrl)
                        ExitLoop
                    EndIf
                EndIf
                Local $hCtrlHandle = ControlGetText($text, '', $ctrl)
                _log4a_Info("Control Text Search: " & $ctrltxt)
                _log4a_Info("Control Text Found: " & $hCtrlHandle)
                If ($hCtrlHandle == $ctrltxt) Then
                    ; we got the handle, so the button is there
                    ; now do whatever you need to do
                    _log4a_Info("Found Formclass: " & $formclass)
                    _log4a_Info("Found Text: " & $text)
                    _log4a_Info("Found Control: " & $ctrl)
                    _log4a_Info("Found Ctrl Txt: " & $ctrltxt)
                    _log4a_Info("Timeout: " & $timeout)
                    _log4a_Info("Time Delay (after click): " & $delayafter)
                    _log4a_Info($ctrl)
                    ControlClick($formclass, '', $ctrl)
                    If ($delayafter > 0) Then
                        Sleep($delayafter)
                    EndIf
                    _log4a_Info("ExitLoop:Normal - " & $ctrl)
                    ExitLoop
                EndIf
            EndIf
        EndIf
    WEnd
    _log4a_Info("_checkClickCtrl():End")
EndFunc   ;==>_checkClickCtrl

log4a is found here

 

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Hey Earthshine am I using this right?  It seems to hang there.  Which I assume means it is not finding the control.

_checkClickCtrl('WindowsForms10.Window.8.app.0.33abd19_r6_ad1', 'Lead King Broadcast Lite Vx2.2', 'CLASS:WindowsForms10.BUTTON.app.0.33abd19_r6_ad1; INSTANCE:18', 'Open',0,0)

https://imgur.com/a/kedd4ea

Edited by marcusawerly
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...