この回答についての活動からしばらく経ちましたが、私はこれと同様の機能を必要とするプロジェクトに取り組んでおり、それは確かに可能であると言えます。私の知る限り、DDKが必要であり、PInvoke
この情報用のC#またはWMIインターフェイスはありません。低レベルのUSBルートハブデバイスを開き、ドライバーIOCTLコマンドをそれらに直接送信する必要があります。
幸いなことに、Microsoftは、すべてのUSBデバイスを完全に列挙し、それらが接続されているポートを正確に表示するC++アプリケーションの例を提供しています。そのアプリケーションはUSBViewサンプルアプリケーションです。
このアプリケーションをコンパイルして実行すると、デバイスが接続されている場所が正確に表示され、そのポートにデバイスを接続すると、同じ場所に表示されることがわかると思います。おそらく、C#アプリケーションが必要な情報を取得するために使用できるいくつかの呼び出しを提供するアンマネージC++DLLを作成する方が簡単かもしれません。
EnumerateHubPorts()
コード内の関数について次のように述べています。
開いているハブへのハンドルとハブのダウンストリームポートの数を指定して、ハブの各ダウンストリームポートに対してIOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX要求を送信し、各ポートに接続されているデバイス(存在する場合)に関する情報を取得します。
これに必要なすべてについてのアイデアを与えるために(1つのポートのみに関心がある場合でも、すべてを上から列挙する必要があります)、enum.c
コードのファイルの上部にリストされているコメントを次に示します。
/*
This source file contains the routines which enumerate the USB bus
and populate the TreeView control.
The enumeration process goes like this:
(1) Enumerate Host Controllers and Root Hubs
EnumerateHostControllers()
EnumerateHostController()
Host controllers currently have symbolic link names of the form HCDx,
where x starts at 0. Use CreateFile() to open each host controller
symbolic link. Create a node in the TreeView to represent each host
controller.
GetRootHubName()
After a host controller has been opened, send the host controller an
IOCTL_USB_GET_ROOT_HUB_NAME request to get the symbolic link name of
the root hub that is part of the host controller.
(2) Enumerate Hubs (Root Hubs and External Hubs)
EnumerateHub()
Given the name of a hub, use CreateFile() to map the hub. Send the
hub an IOCTL_USB_GET_NODE_INFORMATION request to get info about the
hub, such as the number of downstream ports. Create a node in the
TreeView to represent each hub.
(3) Enumerate Downstream Ports
EnumerateHubPorts()
Given an handle to an open hub and the number of downstream ports on
the hub, send the hub an IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX
request for each downstream port of the hub to get info about the
device (if any) attached to each port. If there is a device attached
to a port, send the hub an IOCTL_USB_GET_NODE_CONNECTION_NAME request
to get the symbolic link name of the hub attached to the downstream
port. If there is a hub attached to the downstream port, recurse to
step (2).
GetAllStringDescriptors()
GetConfigDescriptor()
Create a node in the TreeView to represent each hub port
and attached device.
*/