dsng Posted July 2, 2012 Share Posted July 2, 2012 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. expandcollapse popup#include <GuiButton.au3> Local $ret_val Local $step_delay = 1000 ; Run group policy editor ShellExecute("gpedit.msc") 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 WinWaitActive($win_title) 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") EndIf Next $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") EndIf ; 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 Sleep(20) $list_count = ControlListView($win_title, "", $list_id, "GetItemCount") WEnd ; 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") EndIf 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}") WinWaitActive($list_item) $ret_val = MsgBox(1, "test", "Perform test?") If $ret_val = 1 Then ; Set the desired properties Set_Properties() ; Close the properties dialog Sleep($step_delay) ControlClick($list_item, "", "[TEXT:OK]") EndIf ; Close GPE WinWaitActive($win_title) Send("!{F4}") ; "!f!x" should work, but it doesn't in GPE Exit 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 Link to comment Share on other sites More sharing options...
ilynaf Posted June 12, 2014 Share Posted June 12, 2014 The same problem here. Any solution/workaround? Link to comment Share on other sites More sharing options...
BrewManNH Posted June 12, 2014 Share Posted June 12, 2014 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 GudeHow 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 Link to comment Share on other sites More sharing options...
LarsJ Posted June 12, 2014 Share Posted June 12, 2014 This can be done with the UI Automation framework. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now