ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
foreach (ManagementObject currentObject in theSearcher.Get())
{
ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
MessageBox.Show(theSerialNumberObjectQuery["SerialNumber"].ToString());
}
如何获取USB-Stick或USB-HardDrive的内部序列号?
如果我插入Hp或SanDisk Pen Drive,它将显示正确和整个序列号,但如果我插入一些其他笔驱动器意味着它将只显示序列号的第一个数字。为什么会出现这个问题我不知道所以请让我纠正。
答案 0 :(得分:0)
尝试使用...
currentObject["PNPDeviceID"]
代替currentObject["DeviceID"]
修改:将您的查询更改为Select * From __InstanceOperationEvent Within 1 Where TargetInstance ISA 'Win32_DiskDrive' and TargetInstance.InterfaceType='USB'
并检查..