Jump to content
Sign in to follow this  

ControlClick/WinExist not working

Recommended Posts


I'm trying to click a button in a popup window, but have so far failed all attempts. This is the output from Au3Info:

>>>> Window <<<<
Title:  VncViewer Message Box
Class:  #32770
Position:   752, 397
Size:   416, 378
Style:  0x94C800CC
ExStyle:    0x00010101
Handle: 0x00190364

>>>> Control <<<<
Class:  Button
Instance:   1
ClassnameNN:    Button1
Advanced (Class):   [CLASS:Button; INSTANCE:1]
ID: 1
Text:   Close
Position:   278, 265
Size:   84, 23
ControlClick Coords:    69, 17
Style:  0x50010000
ExStyle:    0x00000004
Handle: 0x00160440

>>>> Mouse <<<<
Position:   1102, 701
Cursor ID:  0
Color:  0xD4D0C8

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Failed to get server address !
Info Message

>>>> Hidden Text <<<<

This code does not work for me:

If WinExists("VncViewer Message Box") Then
      ControlClick("VncViewer Message Box", "", "[CLASS:Button ;INSTANCE:1]")

Can someone point out to me what is wrong?

Using the CLASS ID for the window creates an endless loop before I even start the VNC Viewer, so I can not use it.


Share this post

Link to post
Share on other sites

Hi Morten,

  Try to get the Window Handle and use that.

Some error checking helps sometimes too( in the form of a MsgBox )


While 1
    If WinExists("Run") Then
        MsgBox(0, "", "Win now exists")
        $hWnd = WinGetHandle("Run")
        ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:4]")

Share this post

Link to post
Share on other sites

I tried using a msgbox for error checking, but it never pops up. There must be something I do wrong in the IF statement.

Using the same code to look for notepad Works as expected, but not with this window.

Share this post

Link to post
Share on other sites

No MsgBox probably means WinExists cant see the window you have named "VncViewer Message Box"

which means your error check worked :-) you have an error ;-)

could not find where to get the "VncViewer Message Box" to popup but here is a working reproducer that might help you along:

If you run this script, then start VNC Viewer, it will click on the INFO button 2 seconds after the window is registered.

While 1
    If WinExists("VNC Viewer") Then
;~      MsgBox(0, "", "Win now exists")
        $hWnd = WinGetHandle("VNC Viewer")
        Sleep(2000) ; couple of seconds to collect thoughts
        ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:2]")
Edited by l3ill

Share this post

Link to post
Share on other sites


Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().

Using 2 for the number of clicks will send a double-click message to the control - this can even be used to launch programs from an explorer control!

If the user has swapped the left and right mouse buttons in the control panel, then the behaviour of the buttons is different. "Left" and "right" always click those buttons, whether the buttons are swapped or not. The "primary" or "main" button will be the main click, whether or not the buttons are swapped. The "secondary" or "menu" buttons will usually bring up the context menu, whether the buttons are swapped or not.

I also like to ControlFocus on the button, first.


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

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  

  • Create New...