This is all the USB device read from your local machine using C#. I am working in wpf windows application. When i want to read my system USB Device i got this sample code. This code every easy to learn and implement as you want. just copy and past in your application.
public partial class Window1 : Window { public Window1() { InitializeComponent(); } static void Main() { var usbDevices = GetUSBDevices(); foreach (var usbDevice in usbDevices) { Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}", usbDevice.DeviceID, usbDevice.PNPDevideID, usbDevice.Description); } Console.Read(); } static List<USBDeviceInfo> GetUSBDevices() { List<USBDeviceInfo> devices = new List<USBDeviceInfo>(); ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub")) collection = searcher.Get(); foreach (var device in collection) { devices.Add(new USBDeviceInfo( (string)device.GetPropertyValue("DeviceID"), (string)device.GetPropertyValue("PNPDeviceID"), (string)device.GetPropertyValue("Description") )); } collection.Dispose(); return devices; } } class USBDeviceInfo { public USBDeviceInfo(string deviceID, string pnpDeviceID, string description) { this.DeviceID = deviceID; this.PNPDeviceID = pnpDeviceID; this.Description = description; } public string DeviceID { get; private set; } public string PNPDeviceID { get; private set; } public string Description { get; private set; } }
0 comments
Post a Comment