Search code examples
powershellautoit

AutoIt Check box button click


Trying to automate away a warning window when connecting to a remote desktop.

Warning window image

MsgBox inside the If shows I have the handle.

Both the check box and connect are buttons. Instance 1 for the check box. Instance 11 for Connect.

I tried with ControlClick.

my code

Also with GUI button check

GUI check code

Does anyone know what I am doing wrong here? Or of an alternative method to doing the same thing?


Solution

  • Remove the text parameter in the first instance. Did you obtain the controls and are confident they are accurate? If so you're looking for:

    $g_hWnd1 = WinWait("Remote Desktop Connection", "", 5) ;Wait for popup
    If IsHWnd($g_hWnd1) = 1 Then ;if handle is found
       MsgBox(0, "", "First warning handle found", 5) ;notify
       Sleep(2500) ;sleep
       $g_hCheckBox = ControlGetHandle($g_hWnd1, "", "[CLASS:Button; INSTANCE:1]") ;stores checkbox in variable
       _GUICtrlButton_SetCheck($g_hCheckBox, True) ;checks checkbox
       ControlClick($g_hWnd1, "", "[CLASS:Button; INSTANCE:11]") ;selects Connect
    EndIf