1 回答
TA贡献1893条经验 获得超10个赞
由于DeviceNotifyEventArgs
包含序列号,您可以在 WMI 的帮助下使用它来查找设备号。
这是这个答案的改编版本:
// enumerate usb drives
foreach (var drive in new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get())
// find driver with known serial number
if ((string)drive.Properties["SerialNumber"].Value == serialNumber)
// associate partitions with drive
foreach (var partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" + drive["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
// associate logical disk with partition
foreach (var disk in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass = Win32_LogicalDiskToPartition").Get())
Console.WriteLine("Disk=" + disk["Name"]);
确保将所有内容包装到:需要处理using返回的所有搜索器和集合。Get()
- 1 回答
- 0 关注
- 74 浏览
添加回答
举报