C#获取指定usb设备的厂商信息

string vid = "04B4"; 
string pid = "1003"; 

string query = $"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%VID_{vid}%&PID_{pid}%'";

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection devices = searcher.Get();

foreach (ManagementObject device in devices)
{
string manufacturer = device["Manufacturer"] as string;
string description = device["Description"] as string;
string deviceId = device["DeviceID"] as string;

Console.WriteLine("Manufacturer: " + manufacturer);
Console.WriteLine("Description: " + description);
Console.WriteLine("DeviceID: " + deviceId);
}

posted @ 2024-03-01 11:45  奇迹之耀  阅读(115)  评论(0编辑  收藏  举报