Sign in to follow this  
Followers 0
comc49

Looping until error message ends

17 posts in this topic

Hi I am trying to install an update through autoit script and during install there will be 4-6 error messages and I need to click "ok" through all of them. My boss tells me that every new update will bring more error messages so I want to create a loop that clicks through all the error messages. I am really new to autoit so is there any tips?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can add all the possible titles to an array, and loop through this function:

_WinAPI_GetWindow($parentHWND, 6)

it grabs the enabled popup (windows spawned by the parent)...then grab the title of that window, and conditionally act on it based which window it is.

something like:

#include <WinAPI.au3>
While ProcessExists("installer process")
    $hPopup = _WinAPI_GetWindow($parentHWND, 6)
    If $hPopup > 0 Then
        $sTitle = WinGetTitle($hPopup)
        ConsoleWrite($sTitle & @CRLF)
        ; perform action on popup
    EndIf   
WEnd

If all are OK or &OK then this would probably work

#include <WinAPI.au3>

$iPid = Run("installer file")
$parentHWND = ""
$iCurrentPID = 0
Do 
    $aWin = WinList()
    For $i = 0 To UBound($aWin)-1
        _WinAPI_GetWindowThreadProcessId($aWin[$i][1], $iCurrentPID)
        If $iCurrentPID = $iPid Then
            $parentHWND = $aWin[$i][1]
            ExitLoop
        EndIf
    Next
Until IsHWnd($parentHWND)


While ProcessExists($iPid)
    $hPopup = _WinAPI_GetWindow($parentHWND, 6)
    If $hPopup > 0 Then
        $sTitle = WinGetTitle($hPopup)
        ConsoleWrite($sTitle & @CRLF)
        $hControl1 = ControlGetHandle($hPopup, "", "OK")
        $hControl2 = ControlGetHandle($hPopup, "", "&OK")
        If IsHWnd($hControl1) Then
            ControlFocus($hPopup, "", $hControl1)
            ControlClick($hPopup, "", $hControl1)
        ElseIf IsHWnd($hControl2) Then
            ControlFocus($hPopup, "", $hControl2)
            ControlClick($hPopup, "", $hControl2)
        Else
            MsgBox(1,1,"can't find an OK button...you will need to debug")
            Exit
        EndIf
        WinWaitClose($hPopup, "", 10)
    EndIf
WEnd

made some small changes

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.

Share this post


Link to post
Share on other sites

So that code will loop through all the installation titles? What does the number 6 represent?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

number 6 represents returning the 'enabled popup'

This script will spawn the process, get the parent window, and then continually loop until the process ends...clicking on popups that have button = "OK" or "&OK", and exiting if there is no such button (you will need to add logic if this is the case)

from msdn:

GW_ENABLEDPOPUP 6

The retrieved handle identifies the enabled popup window owned by the specified window (the search uses the first such window found using GW_HWNDNEXT); otherwise, if there are no enabled popup windows, the retrieved handle is that of the specified window.

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.

Share this post


Link to post
Share on other sites

jdelaney,

guinness will have a fit if he sees you using "magic numbers" like that! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

the "6" needs to be added to the helpfile, and constants :)


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.

Share this post


Link to post
Share on other sites

jdelaney,

But have you told him yet? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hm.. When I run the .exe created by the script, my powershell hangs.. Is there a way to run the .exe in the background?

Share this post


Link to post
Share on other sites

Can you run autoit script that automates install remotely?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#region ---Au3Recorder generated code Start (v3.3.7.0)  ---

#region --- Internal functions Au3Recorder Start ---

#requireadmin
Run("\\xxx-fs-1.xxx.uxx.edu\software\npp.6.3.3.Installer.exe")


WinWait("Installer Language","Please select a language")
WinActivate("Installer Language","Please select a language")
ControlClick("Installer Language","Please select a language",1)

WinWait("Notepad++ v6.3.3 Setup","Welcome to the Notepad++ v6.3.3 Setup")
WinActivate("Notepad++ v6.3.3 Setup","Welcome to the Notepad++ v6.3.3 Setup")
ControlClick("Notepad++ v6.3.3 Setup","Welcome to the Notepad++ v6.3.3 Setup",1)

WinWait("Notepad++ v6.3.3 Setup","License Agreement")
WinActivate("Notepad++ v6.3.3 Setup","License Agreement")
ControlClick("Notepad++ v6.3.3 Setup","License Agreement",1)

WinWait("Notepad++ v6.3.3 Setup","Choose Install Location")
WinActivate("Notepad++ v6.3.3 Setup","Choose Install Location")
ControlClick("Notepad++ v6.3.3 Setup","Choose Install Location",1)

WinWait("Notepad++ v6.3.3 Setup","Choose Components")
WinActivate("Notepad++ v6.3.3 Setup","Choose Components")
ControlClick("Notepad++ v6.3.3 Setup","Choose Components",1)

WinWait("Notepad++ v6.3.3 Setup","Choose Components")
WinActivate("Notepad++ v6.3.3 Setup","Install")
ControlClick("Notepad++ v6.3.3 Setup","Install",1)


WinWait("Notepad++ v6.3.3 Setup","Completing the Notepad++ v6.3.3 Setup")
WinActivate("Notepad++ v6.3.3 Setup","Completing the Notepad++ v6.3.3 Setup")
ControlClick("Notepad++ v6.3.3 Setup","Completing the Notepad++ v6.3.3 Setup",1203)
ControlClick("Notepad++ v6.3.3 Setup","Completing the Notepad++ v6.3.3 Setup",1)

Exit
#endregion --- Au3Recorder generated code End ---

 

This is my test code to install notepad++ remotely and it fails to install remotely.. Is there a better way to code this? Also is it possible to repackage the Installer file so that instead of having the installer.exe and the autoit script.exe I can have one .exe that can automatically install?
Edited by comc49

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Anyone? Is it possible to automate install remotely through powershell(powershell is just for connecting remotely and running the autoit compiled .exe)?

Edited by comc49

Share this post


Link to post
Share on other sites

comc49,

Please do not bump your own threads within 24 hours - and certainly not twice! :naughty:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You can add all the possible titles to an array, and loop through this function:

_WinAPI_GetWindow($parentHWND, 6)

it grabs the enabled popup (windows spawned by the parent)...then grab the title of that window, and conditionally act on it based which window it is.

something like:

#include <WinAPI.au3>
While ProcessExists("installer process")
    $hPopup = _WinAPI_GetWindow($parentHWND, 6)
    If $hPopup > 0 Then
        $sTitle = WinGetTitle($hPopup)
        ConsoleWrite($sTitle & @CRLF)
        ; perform action on popup
    EndIf   
WEnd

If all are OK or &OK then this would probably work

#include <WinAPI.au3>

$iPid = Run("installer file")
$parentHWND = ""
$iCurrentPID = 0
Do 
    $aWin = WinList()
    For $i = 0 To UBound($aWin)-1
        _WinAPI_GetWindowThreadProcessId($aWin[$i][1], $iCurrentPID)
        If $iCurrentPID = $iPid Then
            $parentHWND = $aWin[$i][1]
            ExitLoop
        EndIf
    Next
Until IsHWnd($parentHWND)


While ProcessExists($iPid)
    $hPopup = _WinAPI_GetWindow($parentHWND, 6)
    If $hPopup > 0 Then
        $sTitle = WinGetTitle($hPopup)
        ConsoleWrite($sTitle & @CRLF)
        $hControl1 = ControlGetHandle($hPopup, "", "OK")
        $hControl2 = ControlGetHandle($hPopup, "", "&OK")
        If IsHWnd($hControl1) Then
            ControlFocus($hPopup, "", $hControl1)
            ControlClick($hPopup, "", $hControl1)
        ElseIf IsHWnd($hControl2) Then
            ControlFocus($hPopup, "", $hControl2)
            ControlClick($hPopup, "", $hControl2)
        Else
            MsgBox(1,1,"can't find an OK button...you will need to debug")
            Exit
        EndIf
        WinWaitClose($hPopup, "", 10)
    EndIf
WEnd

made some small changes

 

So I found out that I can't run the installer from autoit but I have to use psexec. Since I am using psexec to open the installer the autoit script can't access the PID of the installer.. Is there a way to pass in the pid or find the pid of the windows that are open?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Use psexec to excute the script you copy over to the station.  Else, you need to find the parent handle through wingethandle (looped until you find it)...which wouldn't make sense, because then you would need to execute the installer and THEN the autoit script on the target station

Edited by jdelaney
1 person likes this

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.

Share this post


Link to post
Share on other sites

Thanks that works! Now I have to legit testing and see if I can update

Share this post


Link to post
Share on other sites

jdelaney your code only works for popups right? I think in my case its a new window everytime. Also the error messages happen in the middle of the installation so the while loop is going to run infinitely because the finish button won't get pressed

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