Updated 2014-02-05 22:59:24 by RLE

Some examples of using TWAPI with USB.

Enumerate human-friendly names for USB devices

proc usb_enum {} {
  set wmi [wmi_root]
  set devices [$wmi ExecQuery {Select * from win32_usbcontrollerdevice}]
  $devices -iterate -cleanup device {
    set dependent [$device Dependent]
    if {[regexp -nocase {win32_pnpentity\.deviceid="(.*)"} $dependent -> id]} {
      set pnp_entities [$wmi ExecQuery "select * from win32_pnpentity where deviceid='$id'"]
      $pnp_entities -iterate -cleanup pnp_entity {
        puts [$pnp_entity Description]
      }
      $pnp_entities -destroy
    }
  }
  $devices -destroy
  $wmi -destroy
}

(tcl) 170 % usb_enum
USB Root Hub (xHCI)
USB Root Hub
Generic USB Hub
USB Composite Device
Lenovo EasyCamera
Intel(R) Centrino(R) Wireless Bluetooth(R) 4.0 + High Speed Adapter
....