Friday 16 November 2012

How to get Hard Disk Drive Serial Number

Hi Friends,

Last week I was working on one window application. In this application we have to get serial number of Hard Disk Drive.

Following code describes how to get serial number of Hard Disk Drive.

You need to add a reference to System.Management.dll to your project.

  private string GetHDDSerialNumber()
  string harddiskno = "";
  ArrayList hdCollection = new ArrayList();
  ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM   Win32_PhysicalMedia");
  int i = 0;
  foreach(ManagementObject wmi_HD in search.Get())
        // get the hard drive from collection
        HardDrive hd = (HardDrive)hdCollection[i];

        // get the hardware serial no.
        if (wmi_HD["SerialNumber"] == null)
                harddiskno = "No Disk Found";
                harddiskno = wmi_HD["SerialNumber"].ToString();

  return  harddiskno ;


In the above code

Happy Programming ! !
If you have any query mail me to     

Sujeet Bhujbal



No comments:

Post a Comment