Jump to content

Querying windows device manager


 Share

Recommended Posts

Hi,

welcome to forum. Generate a wmi query with scriptomatic. You get an array as result with connected devices which have an ViD or PiD.

Now it's your turn to do what you want with the result.

If you have further problems, post your code and ask for more assistence.

Helpfile or search forum is a good start as well.

#include <array.au3>
;call function with wmi query, get the return into an array
$ardevice = getdevices ()
;show array
_ArrayDisplay ($ardevice)

;Query devices with a ViD or PiD
Func getdevices ()
    ; Generated by AutoIt Scriptomatic
    ;search forum for scriptomatic.au3 to generate WMI Queries by yourself
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    ;return array
    Local $arreturn [1]
    $strComputer = "localhost"
    ;WMI Query string
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DeviceBus", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        ;counter for return array
        $count = 1
        ;loop over objects elements
        For $objItem In $colItems
            ;Has the device a vid or pid
            If StringInStr ($objItem.Dependent, "vid") Or StringInStr ($objItem.Dependent, "pid") Then
                ;then redim array to hold value
                ReDim $arreturn [$count]
                ;assign value to array element, get rid of some descriptions
                ;see helpfile for more information
                $arreturn [$count - 1] = StringReplace ($objItem.Dependent, "\\" & @ComputerName & "\root\cimv2:Win32_PnPEntity.DeviceID=", "")
                ;increase array counter 
                $count += 1
            EndIf
        Next
        ;return result array
        Return $arreturn
    Else
        ; ;-(( no objects found
        MsgBox (0,"", "No VID / PID Device found")
    Endif
EndFunc

;-))

Stefan

Edited by 99ojo
Link to comment
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
 Share

  • Recently Browsing   0 members

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