Search code examples
vb.netserial-number

Get H/D Serial number (Not Volumn Serial Number) for IDE and SATA


How can I read the hard disk serial number for IDE and SATA drives in VB.NET? (I don't want the volume serial number).

This info should be gathered both for XP and Vista if possible without administrative rights.


Solution

  • You can use WMI (Windows Management Instrumentation) like this:

    Dim mos As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
    
    For Each mo As ManagementObject In mos.Get()
        Dim serial As String = mo("SerialNumber").ToString()
    Next
    

    Although, I've read about cases in which no serial number is returned using WMI. Another way to accomplish this would be through Platform Invocation Services (PInvoke).

    This article includes a download in which the author implements CreateFile() and DeviceIoControl() to extract drive information through Interop services in VB .NET.

    To use either of the above outlined methods you will need ADMIN rights, a utility which seems to circumvent this can be found here. If your feeling adventurous the C++/Win32 source code is available for you to peruse. (Check out the function 'ReadPhysicalDriveInNTWithZeroRights()')