Jump to content

Can't Control the Device Manager


Xichael
 Share

Recommended Posts

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

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 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

Link to comment
Share on other sites

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

You can do it programatically probably using SetupDiGetClassDevs+SetupDiEnumDeviceInfo+SetupDiGetDeviceInstanceId+SetupDiSetClassInstallParams+SetupDiCallClassInstaller+SetupDiDestroyDeviceInfoList

Saludos

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

any elegant way. I do a loop from 1 to 100 using controlcommand and checking till get that I wanted.

 

Saludos

Link to comment
Share on other sites

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

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

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

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

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...