Click here to Skip to main content
15,897,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Read Sata Harddisk Serial No. using c#.net
Posted

Using Win32_PhysicalMedia system info, we can get the serial number as:

C#
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

  int i = 0;
  foreach(ManagementObject wmi_HD in searcher.Get())
  {
   // get the hard drive from collection
   // using index
   HardDrive hd = (HardDrive)hdCollection[i];

   // get the hardware serial no.
   if (wmi_HD["SerialNumber"] == null)
    hd.SerialNo = "None";
   else
    hd.SerialNo = wmi_HD["SerialNumber"].ToString();

   ++i;
  }
 
Share this answer
 
You can also try this:
C#
public static string HardDiskID()
{
 ManagementClass partionsClass = new ManagementClass("Win32_LogicalDisk");
 ManagementObjectCollection partions = partionsClass.GetInstances();

 string hdd = string.Empty;

 foreach (ManagementObject partion in partions)
 {
 hdd = Convert.ToString(partion["VolumeSerialNumber"]);

 if (hdd != string.Empty)
 return hdd;
}

return hdd;
}
 
Share this answer
 
If you want a robust solution to read Hard disk serial number, you can try this commerical product
http://www.devlib.net/getdiskserial.htm[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900