jantograaf Posted March 27, 2019 Posted March 27, 2019 (edited) Hi all, I've been search all around this forum for a solution, but so far haven't been able to find one. So I thought I'd explain it as good as possible and ask here for your views on the issue. Situation: I'm trying to automatically (on first run of a newly installed PC for our customers) open the adapter properties of a specific network adapter and then disable all protocols except TCP/IP V4. This is needed for specific functionality with hardware connected to this adapter. I am aware of most of the existing tools (wmic/netsh/devcon/...) to interfere with network adapters, but apart from a WHOLE lot of work in the registry, automating the checkmarks in the properties window should be the fastest solution. System is Windows 10 64-Bit and I've compiled the application as a x64-executable (since I know from the past that the choice between 32- and 64-bit can have consequences for interaction with SysListViews). Let's suppose the adapter is called "ADAPTERXX" (I am aware that my screenshot shows FUJIFILM, but that's from my own PC) Problem: I am perfectly able to automatically open the properties window of the correct adapter using the following code (I know the sending of the keystrokes can be programmed in a little loop, no worries, I'll get to this a little later, this is just a quick draft)... ShellExecute("control.exe","ncpa.cpl",@WindowsDir,"",@SW_SHOW) WinWait("Network Connections","") WinActivate("Network Connections","") WinWaitActive("Network Connections","") Send("{F5}") Sleep(250) BlockInput(1) Send("{A}") Send("{D}") Send("{A}") Send("{P}") Send("{T}") Send("{E}") Send("{R}") Send("{X}") Sleep(500) Send("{APPSKEY}") Sleep(100) Send("{R}") Local $ListWindow = WinWaitActive("ADAPTERXX Properties","") When I arrive in this window, I can detect which specific options has which specific ID in the SysListView32-instance by using: ControlListView("ADAPTERXX Properties","","[CLASSNN:SysListView321]","FindItem","Client for Microsoft Networks") But then, I can't control the checkmark in front of the text and the icon... I've tried lots of solutions. I've tried checking the state, but this next command always returns 'True' Local $GHandle = ControlGetHandle("ADAPTERXX Properties","","[CLASSNN:SysListView321]") MsgBox(0,"Is Item3 checked?",_GUICtrlListView_GetItemChecked($GHandle,3)) I've tried selecting or deselecting, but no result... ControlListView("FUJIFILM Properties","","[CLASSNN:SysListView321]","Deselect",$List_CMN) Creating an array of the window returns an empty array Local $ListArray = _GUICtrlListView_CreateArray($GHandle,Default) If anyone has any ideas, please shoot. It's also something that anyone can try at home with their own 'network properties', just change the ADAPTERXX to another name and the code to select the right adapter in the network connections window (all the little keystrokes). I'm open to any and all suggestions, I'm just at the end of my wits here... Thanks in advance! Jan Edited March 27, 2019 by jantograaf SOLVED! Hurraaaaaah!
LarsJ Posted March 27, 2019 Posted March 27, 2019 A common workaround to get the checked state of a listview item is to test the index of the state image. A checked and unchecked checkbox are two different state images. Usually with indices 2 and 3. But I don't remember it exactly, so please test it. _GUICtrlListView_GetItemStateImage( $hHandle, 3 ) Then you can switch the checked state with these commands: WinActivate WinWaitActive _GUICtrlListView_SetItemSelected( $hHandle, 3, True, True ) ; Selected = True, Focused = True Send( "{SPACE}" ) The code is untested. jantograaf 1 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
jantograaf Posted March 27, 2019 Author Posted March 27, 2019 @LarsJ, you saved the day. A true hero! So after finding the ID of the field I want to check/change using... Local $List_CMN_ID = ControlListView("FUJIFILM Properties","","[CLASSNN:SysListView321]","FindItem","Client for Microsoft Networks") ... now, thanks to you, I've been able to (indeed) read the state of the checkbox by using the following piece of code. The _GUICtrlListView_GetItemStateImage, as you stated, returns 2 for a checked and 3 for an unchecked checkbox (I suppose 1 will be used for grayed out checkboxes in forms where these are applicable). So then, depending on my needs, I can change the state of the checkbox. I wrote a little function to be able to quickly change the state of a found ID to the state I want it to be... Func SetCheckboxState($handle,$checkbox_id,$wantedstate) ;use 2 for enabled and 3 for disabled Local $currentstate = _GUICtrlListView_GetItemStateImage($handle,$checkbox_id) If $currentstate = $wantedstate Then Return Else _GUICtrlListView_SetItemSelected($handle,$checkbox_id,True,True) Send("{Space}") Sleep(50) Return EndIf EndFunc Be aware that I'm a basic programmer so some of my code could probably be a lot more effective using different coding styles, but as long as it works, I'm a happy guy 🙂 Thanks a lot and have a nice day! Greetings from a happy coder! 🕵️♂️ Jan
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