Xichael Posted November 27, 2015 Share Posted November 27, 2015 I've been unable to get AutoIt to interact in any way with the Device Manager. No Send or ControlFocus/Send/Click, whether with a class or a handle. I'm trying to create a script to enable/disable USB devices like my gamepad and webcam with a hotkey or shortcut, rather than having to physically plug/unplug them.In my googling, I found someone who hit a similar dead end a few years ago here on the forum. Back then the advice was to use a 3rd-party device manager called DevManView. I've also read about a command line device manager you can download from Microsoft called DevCon, but if it's possible to achieve this without having to install any extra software, that would be preferred.If someone could post a working example of a script that can successfully navigate to and disable/enable a random device, I'd be very grateful. Link to comment Share on other sites More sharing options...
BrewManNH Posted November 27, 2015 Share Posted November 27, 2015 What are you trying to do in device manager? Almost everything in there can be manipulated without automating the GUI itself, either through the registry or the command line. 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...
TheDcoder Posted November 27, 2015 Share Posted November 27, 2015 What are you trying to do in device manager?I'm trying to create a script to enable/disable USB devices like my gamepad and webcam with a hotkey or shortcut, rather than having to physically plug/unplug them. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Danyfirex Posted November 27, 2015 Share Posted November 27, 2015 You can do it programatically probably using SetupDiGetClassDevs+SetupDiEnumDeviceInfo+SetupDiGetDeviceInstanceId+SetupDiSetClassInstallParams+SetupDiCallClassInstaller+SetupDiDestroyDeviceInfoListSaludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Xichael Posted November 27, 2015 Author Share Posted November 27, 2015 Sounds complicated, and I'm no programmer – though I would love to learn. Are those to be used with DllCall?All my scripts thus far mainly interact with the GUI or command line. Is there some way I can achieve this in more familiar territory?Does anyone know why the Device Manager GUI is so unresponsive to basic things like ControlFocus and Send? Link to comment Share on other sites More sharing options...
TheDcoder Posted November 28, 2015 Share Posted November 28, 2015 I'm no programmer – though I would love to learn.This might help you EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Danyfirex Posted November 28, 2015 Share Posted November 28, 2015 Sounds complicated, and I'm no programmer – though I would love to learn. Are those to be used with DllCall?All my scripts thus far mainly interact with the GUI or command line. Is there some way I can achieve this in more familiar territory?Does anyone know why the Device Manager GUI is so unresponsive to basic things like ControlFocus and Send?maybe you're not running as admin. So you can use a nirsoft commandline app that provide device enable/disable.Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Xichael Posted December 1, 2015 Author Share Posted December 1, 2015 maybe you're not running as admin...That was the problem. I added #RequireAdmin and things are starting to work. Here's what I have so far:#Include <GuiTreeView.au3> #RequireAdmin $sDevice = "Xbox 360 Wireless Receiver for Windows" ShellExecute("devmgmt.msc") WinWaitActive("Device Manager") $hTree = ControlGetHandle("Device Manager", "", "[CLASS:SysTreeView32; INSTANCE:1]") $hItem = _GUICtrlTreeView_FindItem($hTree, $sDevice) _GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET) ControlClick("Device Manager", "", $hTree) ControlClick("Device Manager", "", "[CLASS:ToolbarWindow32; INSTANCE:1]", "", "", 230, 10)At this point, the device is selected and I'm trying to ControlClick the enable/disable button on the toolbar using coordinates provided by Au3Info, but nothing's happening.Anyone have any idea why? Link to comment Share on other sites More sharing options...
Danyfirex Posted December 1, 2015 Share Posted December 1, 2015 Hello. this work for me.#Include <GuiTreeView.au3> #RequireAdmin Local $sDevice = "Xbox 360 Wireless Receiver for Windows" Local $sDevTitle="Device Manager" ShellExecute("devmgmt.msc") WinWaitActive($sDevTitle) $hTree = ControlGetHandle($sDevTitle, "", "[CLASS:SysTreeView32; INSTANCE:1]") $hItem = _GUICtrlTreeView_FindItem($hTree, $sDevice) _GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET) _GUICtrlTreeView_ClickItem($hTree, $hItem) ControlCommand($sDevTitle,"","ToolbarWindow321","SendCommandID",25)Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Xichael Posted December 2, 2015 Author Share Posted December 2, 2015 (edited) Awesome! How'd you get the Command ID? I wasn't able to get anything that specific from Au3Info. Edited December 2, 2015 by Xichael Link to comment Share on other sites More sharing options...
Danyfirex Posted December 2, 2015 Share Posted December 2, 2015 any elegant way. I do a loop from 1 to 100 using controlcommand and checking till get that I wanted. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Xichael Posted December 3, 2015 Author Share Posted December 3, 2015 I just discovered that despite the button being in the same place, enable and disable have different IDs (24 vs 25). Unless there's some way to check the device's status and do an If/Else, a ControlClick on the button's coordinates might be easier. Any idea how to get ControlClick to work on that button? Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted December 3, 2015 Share Posted December 3, 2015 I know you do not want to use DevCon but it really works well for this kind of stuff and you do not need to install it just have it in your script via FileInstall() or on the computer already.If you have Windows 8 or 10 I think they have this now part of Powershell and you can interface with Powershell via Autoit:http://blogs.technet.com/b/wincat/archive/2012/09/06/device-management-powershell-cmdlets-sample-an-introduction.aspx DevCon being such a big thing even the Powershell people used it before those new cmdlets:http://blogs.technet.com/b/heyscriptingguy/archive/2014/05/25/weekend-scripter-use-powershell-to-find-and-disable-webcams.aspx Link to comment Share on other sites More sharing options...
Xichael Posted December 3, 2015 Author Share Posted December 3, 2015 Yeah, I'll probably end up using one of the alternatives at this rate. I'm just surprised this is proving to be so difficult. I've never encountered a GUI so immune to AutoIt's effects. It kind of makes me all the more determined to make it work. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted December 3, 2015 Share Posted December 3, 2015 Im sure we can automate the GUI no problem, it's not because its too hard that I am giving you programmatic solutions, its because its the more desirable solution in most cases because it can be done silently behind the scenes and not interrupt your workflow or be prone to error/failure like GUI automation can.When the standard methods of controlclick and such do not work, usually the IUIAutomation is the next way to go. Link to comment Share on other sites More sharing options...
junkew Posted December 12, 2015 Share Posted December 12, 2015 @DanyFirex: Nice trick to loop thru them all. IuIAutomation and simplespy will give you the numbers directlyI tried with IUIAutomation and it works only when using #RequireAdmin otherwise you get an exception. Tested with simplespy FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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