C# 读取U盘序列号进行验证的示例代码
private List<string> _serialNumber = new List<string>(); public void matchDriveLetterWithSeral() { _serialNumber.Clear(); string[] diskArray; string driveNumber; var searcher = new ManagementObjectSearcher("select * from Win32_LogicalDiskToPartition"); foreach (ManagementObject dm in searcher.Get()) { getValueInQuotes(dm["Dependent"].ToString()); diskArray = getValueInQuotes(dm["Antecedent"].ToString()).Split(','); driveNumber = diskArray[0].Remove(0, 6).Trim(); var disks = new ManagementObjectSearcher("select * from Win32_DiskDrive"); foreach (ManagementObject disk in disks.Get()) { if(disk["Name"].ToString()==("\\\\.\\PHYSICALDRIVE"+driveNumber)&&disk["InterfaceType"].ToString()=="USB") { _serialNumber.Add(parseSerialFromDeviceID(disk["PNPDeviceID"].ToString())); } } } }
以上是C# 讀取U碟序號進行驗證的範例程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!