jwinters Posted August 10, 2022 Posted August 10, 2022 I am trying to automate some additional setup for a program after installation that involves Device Manager. The end goal is to expand Network adapters, right click "Intel(R) PRO/1000 MT Desktop Adapter", and select Update driver, continuing through additional update screens from there. Since the options that appear in Device Manager can change, I'm trying to get to this point by using the names of the child items on the tree, I found using the general dropdown location and a window offset to be too inconsistent. My current problem is that the names of the items in the tree are all appearing as empty strings, so even though I am able to run through a loop and expand each child item, my script has no way of telling them apart. I threw the code attached together as a test of the functionality of the _GUICtrlTreeView functions so I don't think the array math is perfect, but it works for now. Also, any way of getting to the screen that appears after pressing Update driver would be appreciated, this is just the best way I've found to get there. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <Array.au3> Global Const $DEVICE_MAN_TITLE = "[TITLE:Device Manager; CLASS:MMCMainFrame]" Global Const $DM_TIMEOUT = 60 ; Seconds Example() Func Example() Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE) Local $hWnd = WinWaitActive($DEVICE_MAN_TITLE, "", $DM_TIMEOUT) ;Timeout error messages here Local $treeView = ControlGetHandle($DEVICE_MAN_TITLE, "", "[CLASS:SysTreeView32; INSTANCE:1]") Local $firstItemHandle = _GUICtrlTreeView_GetFirstItem($treeView) Local $childCount = _GUICtrlTreeView_GetChildCount($treeView, $firstItemHandle) Local $names[$childCount + 3] $names[0] = _GUICtrlTreeView_GetText($firstItemHandle) Local $childItemHandle = _GUICtrlTreeView_GetFirstChild($treeView, $firstItemHandle) $names[1] = _GUICtrlTreeView_GetText($childItemHandle) For $i = 0 To $childCount _GUICtrlTreeView_Expand($treeView, $childItemHandle) ;to make sure childItemHandle update works Local $nextChildHandle = _GUICtrlTreeView_GetNextChild($treeView, $childItemHandle) $nextChildName = _GUICtrlTreeView_GetText($nextChildHandle) If($nextChildName <> "") Then $names[$i + 2] = $nextChildName Else $names[$i + 2] = $i + 2 EndIf $childItemHandle = $nextChildHandle Next _ArrayDisplay($names) EndFunc
TheXman Posted August 10, 2022 Posted August 10, 2022 (edited) Why not try devcon.exe, the command line version of the Windows Device Manager? It's probably easier and more reliable than trying to work with the Device Manager GUI . To get a list of the network adapters and their hwid's, you can execute the following command and parse the output: devcon find =net Sample output: =============== ROOT\MS_AGILEVPNMINIPORT\0000 : WAN Miniport (IKEv2) ROOT\MS_L2TPMINIPORT\0000 : WAN Miniport (L2TP) ROOT\MS_NDISWANBH\0000 : WAN Miniport (Network Monitor) ROOT\MS_NDISWANIP\0000 : WAN Miniport (IP) PCI\VEN_10EC&DEV_8168&SUBSYS_05B71028&REV_0C\010000000000001234: Realtek PCIe GBE Family Controller PCI\VEN_168C&DEV_0032&SUBSYS_02091028&REV_01\4&9A48CD4&0&00E7: Dell Wireless 1703 802.11b/g/n (2.4GHz) ROOT\MS_NDISWANIPV6\0000 : WAN Miniport (IPv6) ROOT\*ISATAP\0000 : Microsoft ISATAP Adapter To update the driver for a given adapter, you could execute something like: devcon update <inf> "PCI\VEN_10EC&DEV_8168&SUBSYS_05B71028&REV_0C" If you need more information about devcon.exe, then you can start HERE. Edited August 11, 2022 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
jwinters Posted August 11, 2022 Author Posted August 11, 2022 That program might get to the point I need, but I'm not sure I'd have a consistent way of installing it initially. I've found the cab files to install just devcon without the WDK, as my script tries to use the smallest file size possible, but the different files to install for different windows updates is where it becomes a problem. The computers this will be run on won't have an internet connection during the setup, so I won't be able to automate some way to find the most recent version online. The version of windows on each of these computers could also be different between each, so while I could have it choose the correct file based on which older version of windows is installed, I won't be able to continually update it for the newest available files. Is there anything similar to this that doesn't have a continuously changing installation method?
TheXman Posted August 11, 2022 Posted August 11, 2022 (edited) You are doing a lot of talking and speculation without doing any testing. Instead of saying "I'm not sure..", why don't you find out for yourself and remove any doubt? Devcon.exe is a standalone executable and the Windows7 version runs fine on Windows10. The version on my PC's, v5.2.3178.0, is only 55KB. The Windows7 version might run fine on Windows11 too but, I have no idea because I don't/won't run Windows11 on any of my PC's. In any case, all you would need to do is extract the executable to the workstation during the execution of your script. You could use AutoIt's FileInstall() function to add it to your script & extract it to the workstation. If you don't want to leave the executable on the workstation, you can just delete it when your script exits. Edited August 11, 2022 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Zedna Posted August 11, 2022 Posted August 11, 2022 You can try to use ControlTreeView(). Also try to compile your script as 64bit if you run it on 64bit Windows, because of this remark for ControlTreeView() in helpfile: Quote As AutoIt is a 32-bit application some commands are not available when referencing a 64-bit application as Explorer when running on 64-bit Windows. Resources UDF ResourcesEx UDF AutoIt Forum Search
jwinters Posted August 15, 2022 Author Posted August 15, 2022 With the long list of possible devcon download files for each major Windows update, I feel like thinking the reason they were different was because older ones weren't compatible with new updates was a pretty fair guess to make. I've been trying devcon, and while I can use it to find that list of adapters and their id's, I haven't been able to run it and update an adapter. Removing any scripting to make sure it works on its own, I've been using this: devcon update "C:\Program Files\Path to inf\correctFile.inf" "PCI\VEN_10EC&DEV_8168&SUBSYS_05B71028&REV_0C" with the PCI part being different, just using the same example given earlier, as well as running as an administrator. This gives me "devcon failed", and everywhere I've found so far has pointed me to C:\Windows\inf\setupapi.dev.log as the file to find more specific devcon error information. However, every time I run this command, I reopen this file (it's not open at all while the command runs) and there isn't any information listed related to this error. I've tried PnPUtil as well, since it's built into Windows and seems to be designed for a similar purpose. I've used Get-ChildItem $infPath -Recurse -Filter "*.inf" | ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install } which results in the "Driver package added successfully" message, but no actual change to the network adapters in device manager after restarting the computer. I'm not sure if I'm missing a step with fully adding it after, or if this isn't the intended purpose of the program as it uses the command add driver instead of any "update" phrasing. Trying the delete-driver command for the one that needs to be updated followed by this add driver line didn't seem to work correctly either. I have tried using ControlTreeView(), but this still creates a similar problem for me since all the items in the tree have no name available (or that they're all empty strings). From the examples in the documentation, I would look for the correct dropdown in the tree with this function using the option1 parameter. The examples all are similar to this: ControlTreeView($hGUI, "", $hTreeView_1, "Exists", "Root|Item 4") relying on having a name to match with after the root. The program does know the different tabs exist, so I could iterate through them change their name from "" to what I think they are, but since the items in device manager can change it would be as inconsistent as sending a MouseClick() to the location network adapters is found on the test computer. I did also try compiling the script as 64bit, and while I can't promise I did it correctly it didn't make any differences that I could see.
rsn Posted August 15, 2022 Posted August 15, 2022 Whenever I scripted devcon in the past, I trimmed everything after the device ID. If it were: "PCI\VEN_10EC&DEV_8168&SUBSYS_05B71028&REV_0C" I'd only send the following to devcon: "PCI\VEN_10EC&DEV_8168" Also, depending on the device, an updated driver bundle may not have an update for a particular device. Intel network adapters bundles tend to do this.
jwinters Posted August 15, 2022 Author Posted August 15, 2022 Are you deciding where to stop that shortened version based on where the second & is? When I tried changing mine to the same format I got the same error as before, but I'm not sure if that's the stopping point you meant. I'm also not sure what you meant about an updated driver bundle. If it helps, I am installing a program, then finding an .inf file within the directories installed to use for updating the Intel(R) PRO/1000 MT Desktop Adapter. I'm not very familiar with how drivers and their updates work, but when I manually did this setup the Intel adapter name is completely replaced which makes me believe it is able to be updated in some way, so I'm trying to duplicate that with a script.
rsn Posted August 17, 2022 Posted August 17, 2022 (edited) Years ago I wrote an windows command/AutoIt script to update NIC and video drivers for the PCs where I work. I spent a fair amount of time studying the inf files to see how they worked. Anyway, the shortened string is just the vendor (VEN) and device (DEV) IDs. The subsystem (SUBSYS) and hardware revision (REV) IDs tend to be more to uniquely identify the hardware than to be particularly useful for the driver install. The devcon command I just tested is formatted as follows (running as admin): devcon.exe update "c:\temp\intel\e1d68x64.inf" "PCI\VEN_8086&DEV_15FB" Edited August 17, 2022 by rsn Tested
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