发表评论
using System; using System.Collections.Generic; using System.Management; using System.Text; namespace Basic { public class USBDeviceInfo { public USBDeviceInfo(string deviceID, string pnpDeviceID, string description, string manufacturer, string[] hardwareID,string caption) { this.DeviceID = deviceID; this.PnpDeviceID = pnpDeviceID; this.Description = description; this.Manufacturer = manufacturer; this.HardwareID =hardwareID; this.Caption = caption; } public string DeviceID { get; private set; } public string PnpDeviceID { get; private set; } public string Description { get; private set; } public string[] HardwareID { get; private set; } public string Manufacturer { get; private set; } public string Caption { get; private set; } } public class GetUsbInfo { public static List<USBDeviceInfo> GetUSBDevices() { List<USBDeviceInfo> devices = new List<USBDeviceInfo>(); ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity"+" WHERE Manufacturer='Advantech'")) collection = searcher.Get(); foreach (var device in collection) { devices.Add(new USBDeviceInfo( (string)device.GetPropertyValue("DeviceID"), (string)device.GetPropertyValue("PNPDeviceID"), (string)device.GetPropertyValue("Description"), (string)device.GetPropertyValue("Manufacturer"), (string[])device.GetPropertyValue("HardwareID"), (string)device.GetPropertyValue("Caption") )); } collection.Dispose(); return devices; } } }
咨询电话
0371-68632068