Jump to content

Recommended Posts

Posted

Hello.  Recently, I have been really getting into building chocolatey packages for automated software deployments, and, as one would expect, all submissions have to be fully automated.  If the software that one wants to incorporate into a chocolatey package does not have a way to silently install, then one must use a scripting language like autoIT to automate the installation by automating the interaction with the controls of installer.  However, if I were to do this, I would want to hide the installer's GUI from view so that the user can't directly interact with it and potentially screw it up, and we know we can accomplish this by simply passing @SW_HIDE to the show_flag argument in the run function, but, once we have gotten to this point where we have launched an application whose GUI has been hidden by the run command, is there a way for autoIT to interact with the controls of that hidden GUI the same way that it would if the GUI was visible?  How would you even go about identifying the window?  Sure, you can launch the installer normally and use the window info tool to pull the information, but when your script launches it and the window is hidden, does the window really exist if it is hidden?  Will "Winactivate" by able to "activate" a hidden window?  Below is an example of code that demonstrates what I mean:
 

; Running the below code works because passing @SW_SHOW to the show flag parameter will launch the application with a visible GUI
; Change "@SW_SHOW" to "@SW_HIDE", and the script no longer works.
$enabled = False
Run ( "C:\Program Files (x86)\Program\Program.exe", @SystemDir, @SW_SHOW )
WinWait ( "Program", "OK" )
WinActivate ( "Program", "OK" )
WinWaitActive ( "Program", "OK" )
If ControlCommand ( "Program", "OK", "[CLASS:Button; INSTANCE:3]", "IsChecked", "" ) = 0 Then
    $enabled = False
    ControlClick ( "Program", "OK", "[CLASS:Button; INSTANCE:3]" )
Else
    $enabled = True
EndIf

ControlClick ( "Program", "OK", "[CLASS:Button; INSTANCE:4]" )

Very interested in hearing your thoughts.  Oh, and one more thing that I didn't notice until I was writing up this forum post actually.  I think the documentation for the "run" function might be wrong.  Below we see documentation for the the most up-to-date version of autoit's run function:

Ehu8wNC.png

As you can see, the documentation states that the "show_flag" parameter's default value is "@SW_HIDE", but this does not actually seem to be the case, as running the above example code above without any show_flag parameter results in a visible GUI.  Wouldn't that make the default value "@SW_SHOW"? 

Posted (edited)

Ok. This is your "Program"

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    ; Running the below code works because passing @SW_SHOW to the show flag parameter will launch the application with a visible GUI
    ; Change "@SW_SHOW" to "@SW_HIDE", and the script no longer works.
    $enabled = False
    Run ( "C:\Program Files (x86)\Program\Program.exe", @SystemDir, @SW_SHOW )
    WinWait ( "Program", "OK" )
    WinActivate ( "Program", "OK" )
    WinWaitActive ( "Program", "OK" )
    If ControlCommand ( "Program", "OK", "[CLASS:Button; INSTANCE:3]", "IsChecked", "" ) = 0 Then
        $enabled = False
        ControlClick ( "Program", "OK", "[CLASS:Button; INSTANCE:3]" )
    Else
        $enabled = True
    EndIf

    ControlClick ( "Program", "OK", "[CLASS:Button; INSTANCE:4]" )

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

;~ HotKeySet("{ESC}", "Terminate")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Program", 400, 100, 100, 100)
$Button1 = GUICtrlCreateButton("OK", 8, 8, 75, 25)
$Checkbox1 = GUICtrlCreateCheckbox("HideMe", 100, 10, 95, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Bttn3", 200, 10, 95, 17)
$Button2 = GUICtrlCreateButton("Close", 300, 8, 75, 25)
$Edit1 = GUICtrlCreateEdit("OK" & @CRLF & "You can close this from the tray if you must", 8, 38, 400 - 16, 100 - 38 - 8)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

ToolTip((GUICtrlRead($Checkbox2) = 1 ? "GUI_CHECKED" : "UNCHECKED"), 50, 50, "Program")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button2
            Terminate()
        Case $Checkbox2
            ToolTip((GUICtrlRead($Checkbox2) = 1 ? "GUI_CHECKED" : "UNCHECKED"), 50, 50, "Program")
        Case $Checkbox1
            WinSetState("Program", "OK", @SW_HIDE)
    EndSwitch
WEnd

Func Terminate()
    GUIDelete()
    Exit
EndFunc   ;==>Terminate

and this is what is missing from your code

Opt("WinDetectHiddenText", 1)

 

And !, thanks for the help file review :) 

 

Edit: do add a timeout

If Not WinWait ( "Program", "OK", 5 ) Then Exit 5 ; 5 secs should be enough I guess

 

Edited by argumentum
more

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

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
  • Recently Browsing   0 members

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