List USB devices
from http://csharphelper.com/blog/2017/08/list-usb-devices-in-c/
This program uses WMI (Windows Management Instrumentation) to query for USB devices. To use WMI, add a references to System.Management and add a using System.Management directive.
When it starts, this example uses the following code to list USB devices.
// Add a reference to System.Management. using System.Management; ... private void Form1_Load(object sender, EventArgs e) { ManagementObjectSearcher device_searcher = new ManagementObjectSearcher("SELECT * FROM Win32_USBHub"); foreach (ManagementObject usb_device in device_searcher.Get()) { textBox1.Text += usb_device.Properties["DeviceID"].Value.ToString() + " " + usb_device.Properties["PNPDeviceID"].Value.ToString() + " " + usb_device.Properties["Description"].Value.ToString() + " " + Environment.NewLine; } }
留言
張貼留言