Home > Backend Development > C#.Net Tutorial > C# sample code for reading USB flash drive serial number for verification

C# sample code for reading USB flash drive serial number for verification

黄舟
Release: 2017-03-10 13:38:51
Original
2632 people have browsed it

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(&#39;,&#39;);
                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()));
                    }
                }
            }
        }
Copy after login

The above is the detailed content of C# sample code for reading USB flash drive serial number for verification. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template