Jump to content
Sign in to follow this  

How to check/uncheck WindowsForms10.Button check boxes

Recommended Posts


I'm trying to automate the setting of some items in a local Group Policy Editor by running gpedit.msc. (The computers are not connected to a domain.) The Properties dialogs contain check-box buttons of class WindowsForms10.BUTTON... I want to be able to check or uncheck the buttons.

I've tried several things. The ControlCommand function with IsChecked always returns 0 whether the button is checked or unchecked. The ControlCommand function with Check toggles the check-box instead of always setting it to checked (i.e. it is like clicking on the button). The ControlCommand function with UnCheck does not seem to do anything.

The _GUICtrlButton_GetCheck and _GUICtrlButton_GetState functions seem to always return 0. The _GUICtrlButton_SetCheck function does not seem to do anything.

I've searched the forum some, and the problem seems to be that these buttons are not standard Win32 API buttons.

Is there a way to check and uncheck these buttons?

Here is what AutoIt Info shows about one of the buttons:

Class: WindowsForms10.BUTTON.app.0.283d742

Instance: 1

ClassnameNN: WindowsForms10.BUTTON.app.0.283d7421

Name: defineAuditSettings

Advanced (Class): [NAME:defineAuditSettings]

ID: 66292

Text: &Configure the following audit events:

Position: 25, 117

Size: 396, 24

ControlClick Coords: 125, 11

Style: 0x5601000B

ExStyle: 0x00000000

Handle: 0x00000000000102F4

Here is the code that I used to test the various functions. The key part is in the Set_Properties function.

#include <GuiButton.au3>
Local $ret_val
Local $step_delay = 1000

; Run group policy editor
Local Const $win_title = "Local Group Policy Editor"
Local Const $top_tree_key = "Local Computer Policy"
Local Const $tree_id = "[CLASSNN:SysTreeView321]"
Local Const $list_id = "[CLASSNN:SysListView321]"
Local Const $extd_stnd_id = "[CLASSNN:AMCCustomTab1]"

Local $control_column[2] = ["Computer Configuration -> Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> System Audit Policies - Local Group Policy Object -> Account Logon", "Audit Credential Validation"]

; Split up the tree key into tree levels based on the string " -> " as a delimiter
Local $tree_key = StringSplit($control_column[0], " -> ", 1)

; Expand each tree level except the last, and then select the last
ControlFocus($win_title, "", $tree_id)
Local $tree_item = $top_tree_key
For $i = 1 To $tree_key[0] - 1
    $tree_item = $tree_item & "|" & $tree_key[$i]
    ControlTreeView($win_title, "", $tree_id, "Expand", $tree_item)
    If @error = 1 Then
        Error_Exit("tree item " & $tree_item & " not found")
$tree_item = $tree_item & "|" & $tree_key[$tree_key[0]]
ControlTreeView($win_title, "", $tree_id, "Select", $tree_item)
If @error = 1 Then
    Error_Exit("tree item " & $tree_item & " not found")

; Sometimes it takes a little while for the list to be populated. So loop until the number of items is
; greater than 0.
ControlFocus($win_title, "", $list_id)
Local $list_count = ControlListView($win_title, "", $list_id, "GetItemCount")
While $list_count = 0
    $list_count = ControlListView($win_title, "", $list_id, "GetItemCount")

; Clear any previous selection in this list, and then find and select the list item.
ControlListView($win_title, "", $list_id, "SelectClear")
Local $list_item = $control_column[1]
Local $list_item_ndx = ControlListView($win_title, "", $list_id, "FindItem", $list_item)
If $list_item_ndx = -1 Then
    Error_Exit("list item " & $list_item & " not found")
ControlListView($win_title, "", $list_id, "Select", $list_item_ndx)

; Hit Enter on the list item to display the properties dialog
ControlSend($win_title, "", $list_id, "{ENTER}")
$ret_val = MsgBox(1, "test", "Perform test?")
If $ret_val = 1 Then
    ; Set the desired properties
    ; Close the properties dialog
    ControlClick($list_item, "", "[TEXT:OK]")

; Close GPE
Send("!{F4}") ; "!f!x" should work, but it doesn't in GPE

Func Set_Properties()
    Local $ret_val
    Local $button_text = "&Configure the following audit events:"

    $ret_val = ControlCommand($list_item, "", "[TEXT:" & $button_text & "]", "IsChecked")
    MsgBox(0, "debug", "ControlCommand/IsChecked return " & $ret_val & ", @error " & @error)

    $ret_val = ControlCommand($list_item, "", "[TEXT:" & $button_text & "]", "Check")
    MsgBox(0, "debug", "ControlCommand/Check return " & $ret_val & ", @error " & @error)

    $ret_val = ControlCommand($list_item, "", "[TEXT:" & $button_text & "]", "UnCheck")
    MsgBox(0, "debug", "ControlCommand/UnCheck return " & $ret_val & ", @error " & @error)

    Local $button_hnd = ControlGetHandle($list_item, "", "[TEXT:" & $button_text & "]")
    $ret_val = _GUICtrlButton_GetCheck($button_hnd)
    MsgBox(0, "debug", "_GUICtrlButton_GetCheck return " & $ret_val & ", @error " & @error)

    $ret_val = _GUICtrlButton_GetState($button_hnd)
    MsgBox(0, "debug", "_GUICtrlButton_GetState return " & $ret_val & ", @error " & @error)

    $ret_val = _GUICtrlButton_SetCheck($button_hnd)
    MsgBox(0, "debug", "_GUICtrlButton_SetCheck return " & $ret_val & ", @error " & @error)
EndFunc ;==>Set_Properties

Func Error_Exit($error_msg)
    MsgBox(0, "Error", $error_msg)
    Exit 1
EndFunc ;==>Error_Exit

Share this post

Link to post
Share on other sites

The same problem here. Any solution/workaround?

Share this post

Link to post
Share on other sites

A little more information is needed, what exactly are you trying to do, what isn't working, and what have you tried?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.