Sign in to follow this  
Followers 0
ucmerrill

Device Manager

5 posts in this topic

Hi All,

I found this very userful code within the forum. Please see below:

#Include <GuiTreeView.au3>

ShellExecute('devmgmt.msc')

WinWaitActive("Device Manager")

$hTree = ControlGetHandle("Device Manager", "", "[Class:SysTreeView32;Instance:1]")

$hItem = _GUICtrlTreeView_FindItem($hTree, "USB-to-Serial(com1)")

_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)

The part that has "USB-to-Serial(com1)") can change to USB-to-Serial(com4)") or some other com# .

My question is how do I do an instring or some other method to find a partial name like "USB-to-Serial" and then send the enter key if the name is found.

Any help will greately be appreciated.

ucmerrill

Share this post


Link to post
Share on other sites



_GuiCtrlTreeView_FindItem() will do a partial match, see the third parameter for the function in the help file.

:unsure:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

_GuiCtrlTreeView_FindItem() will do a partial match, see the third parameter for the function in the help file.

:unsure:

Share this post


Link to post
Share on other sites

Hi PsaltyDS,

Thanks for the reply and suggestion. Please see the below code on Line 5 "$hItem = _GUICtrlTreeView_FindItem($hTree[,$fInStr = "USB-to-Serial Comm Port"])"

I've tried to no avail. Can anyone assit or correct the below code. Any help will be greately appreciated. Thanks.

#Include <GuiTreeView.au3>

ShellExecute('devmgmt.msc')

WinWaitActive("Device Manager")

$hTree = ControlGetHandle("Device Manager", "", "[Class:SysTreeView32;Instance:1]")

$hItem = _GUICtrlTreeView_FindItem($hTree[,$fInStr = "USB-to-Serial Comm Port"])

_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)

; Focus treeview and Send Enter

ControlFocus("Device Manager", "", $hTree)

ControlSend("Device Manager", "", $hTree, "{ENTER}")

Share this post


Link to post
Share on other sites

That is invalid syntax. You don't use the square brackets around the parameters. They are only used in the help file to indicate optional parameters. You also don't use the variable name of the parameter (i.e. "$fInStr"), just provide the value for it.

So that should be:

$hItem = _GUICtrlTreeView_FindItem($hTree, "USB-to-Serial Comm Port", True)

There is no way you passed that through the syntax checker and didn't get failures.

:unsure:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0