This article describes the method of obtaining hard disk number in C#. Share it for your reference. The specific implementation method is as follows:
ManagementClass mc = new ManagementClass("Win32_PhysicalMedia"); //Win32_DiskDrive does not contain the SerialNumber attribute.ManagementObjectCollection moc = (); string strID = null ; foreach( ManagementObject mo in moc ) { strID = ["SerialNumber"].(); break; } += "Hard disk ID:" + strID;
I hope this article will be helpful to everyone's C# programming.