1

I am using following function to get serial number of Harddisk but some time this function returns value in text and some time in hex format?

Please suggest the way to get the serial number in plain text always?

public static string GetHddSerialNo()
{
    string serial = string.Empty;
    ManagementObjectSearcher mos = 
                  new ManagementObjectSearcher ("SELECT * FROM 
                      Win32_PhysicalMedia  WHERE Tag like '%PHYSICALDRIVE0%'");

    foreach (ManagementObject mo in mos.Get())
    {
         serial = Convert.ToString(mo["SerialNumber"]);
         break;
    }

    return serial.Trim();
}
Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61
Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
  • May http://stackoverflow.com/questions/4084402/get-hard-disk-serial-number can help you fix your problem. – brothers28 Jan 20 '14 at 09:37
  • @brothers28 all of the solution are similar to mine. The solution from Azhar to add "HardwareIDExtractorC.dll" does not work. it says that it's not a com component. – Romil Kumar Jain Jan 20 '14 at 09:48

0 Answers0