none
C# and S.M.A.R.T Information about Hard Disk Drive RRS feed

  • Question

  •  

    Hey Guys, Gals.

     

    I am tryinig to develop a program in C#, using VS 2008 to run on either XP or Vista.

     

    The program spec is as follows:

     

    - To be able to return correct Serial Number from Hard Disk Drive or Attached Storage. The Serial Number is the manufacturers number not volume Number.

     

    The problems i am facing:

     

    - Win32_LogicalDisk, and Win32_PhysicalMedia, will return either volume serial number or nothing at all.

     

    Through research, I came across this program:

    http://www.alexnolan.net/software/driveman.htm

     

    Which provides the S.M.A.R.T information of the hard disk drive, which portrays the correct Serial Number. The SMART info is extremely unique and is really what I think I am looking to achieve.

     

    I am therefore considering this approach, but wouldnt know where to start.

    Does anyone have any suggestions on how to incorporate C# and SMART in order to get this outcome? Or is this overboard?


    Cheers,

     

    Ian.

    Monday, April 7, 2008 8:05 AM

Answers

  • novadon,

     

    Based on your post, you would like to get the hard disk drive information by retrieving the S.M.A.R.T instead of the Serial Number info. I would like to provide you the suggestions as follows:

     

    1. I notice you have posted a similar question in Getting S.M.A.R.T attributes from C# using WMI. I have no idea whether you are familiar with WMI, however, you can download the WMI Administrative Tools in the link below:

     

    http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en

     

    2. An example on DeviceIoControl: Get a SMART Drive Serial Number from the thread Retrieving Hard Drive Temperature (S.M.A.R.T)

     

    You can easily translate the VB.NET code to C# here...

     

    3. Win32_PhysicalMedia class is also the WMI class that represents any type of documentation or storage medium, such as tapes, CD ROMs, and so on. Except your original example, I would like to provide you another example in this thread: Retive drive serial number when selected from combo box

     

    Code Snippet

            //Gets the harddisk manufacturer serial number

            private string getHDDID()

            {

                string rValue = null;

                ManagementObjectSearcher searcher;

                ArrayList hddCollection = new ArrayList();

                try

                {

                    searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

                    foreach (ManagementObject wmiObj in searcher.Get)

                    {

                        HardDrive hdd = new HardDrive();

                        hdd.model = wmiObj("Model").ToString;

                        hdd.type = wmiObj("InterfaceType").ToString;

                        hddCollection.Add(hdd);

                        break; // TODO: might not be correct. Was : Exit For

                    }

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                try

                {

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

                    foreach (ManagementObject wmiObj in searcher.Get)

                    {

                        if (wmiObj("SerialNumber") != null)

                        {

                            rValue = wmiObj("SerialNumber").ToString;

                            break; // TODO: might not be correct. Was : Exit For

                        }

                        else

                        {

                            rValue = GetVolumeSerial("C");

                            break; // TODO: might not be correct. Was : Exit For

                        }

                    }

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                return rValue;

            }

     

     

    Hope that can provide you some idea.
    Wednesday, April 9, 2008 8:26 AM

All replies

  • novadon,

     

    Based on your post, you would like to get the hard disk drive information by retrieving the S.M.A.R.T instead of the Serial Number info. I would like to provide you the suggestions as follows:

     

    1. I notice you have posted a similar question in Getting S.M.A.R.T attributes from C# using WMI. I have no idea whether you are familiar with WMI, however, you can download the WMI Administrative Tools in the link below:

     

    http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en

     

    2. An example on DeviceIoControl: Get a SMART Drive Serial Number from the thread Retrieving Hard Drive Temperature (S.M.A.R.T)

     

    You can easily translate the VB.NET code to C# here...

     

    3. Win32_PhysicalMedia class is also the WMI class that represents any type of documentation or storage medium, such as tapes, CD ROMs, and so on. Except your original example, I would like to provide you another example in this thread: Retive drive serial number when selected from combo box

     

    Code Snippet

            //Gets the harddisk manufacturer serial number

            private string getHDDID()

            {

                string rValue = null;

                ManagementObjectSearcher searcher;

                ArrayList hddCollection = new ArrayList();

                try

                {

                    searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

                    foreach (ManagementObject wmiObj in searcher.Get)

                    {

                        HardDrive hdd = new HardDrive();

                        hdd.model = wmiObj("Model").ToString;

                        hdd.type = wmiObj("InterfaceType").ToString;

                        hddCollection.Add(hdd);

                        break; // TODO: might not be correct. Was : Exit For

                    }

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                try

                {

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

                    foreach (ManagementObject wmiObj in searcher.Get)

                    {

                        if (wmiObj("SerialNumber") != null)

                        {

                            rValue = wmiObj("SerialNumber").ToString;

                            break; // TODO: might not be correct. Was : Exit For

                        }

                        else

                        {

                            rValue = GetVolumeSerial("C");

                            break; // TODO: might not be correct. Was : Exit For

                        }

                    }

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                return rValue;

            }

     

     

    Hope that can provide you some idea.
    Wednesday, April 9, 2008 8:26 AM
  • Hi Novadon,

    Did you manage to get this working with the temperature and using the windows api?
    If so can you please post the code or send it to me?

    I have been looking for something similar for a long time now but haven't found a lot, only some c++ code.

    Thanks,
    Jonas
    Saturday, December 6, 2008 1:18 PM