USB Port Monitoring Control
USB Monitoring Control - USB Device Data Monitoring ActiveX Component Library

How to Enumerate USB Devices

HHD Software - Hex Editor Serial Port Monitor USB Protocol Analyzer Network Monitor
 
 
 
< PreviousTopNext >

This section describes the steps you need to carry in order to enumerate the USB devices installed on the computer.

  1. Initialize the usbMonitor object, as described in the this tutorial.
  2. Obtain the pointer to the IDeviceCollection interface of the USB device collection object by taking the value of the IUsbMonitor.Devices property:
    C++
    CComPtr<IDeviceCollection> pDeviceCollection;
    pUsbMonitor->get_Devices(&pDeviceCollection);
    

    C#
    DeviceCollection devices=sm.Devices;
    
  3. Get the value of the IDeviceCollection.Count property:
    C++
    ULONG Count;
    pDeviceCollection->get_Count(&Count);
    

    C#
    uint Count=devices.Count;
    
  4. Cycle through all items of the collection:
    C++
    for (int i=0;i<Count;i++)
    {
        CComPtr<IDevice> pDevice;
        pDeviceCollection->get_Item(CComVariant(i),&pDevice);
        // ...
    } 
    

    C#
    for (int i=0;i<Count;i++)
    {
        Device device=devices[i];
        // ...
    }  
    

    Or...

    C#
    foreach (Device device in devices)
    {
        // ...
    }  
    
< PreviousTopNext >
Copyright © 2011 HHD Software. All rights reserved.