Get Hard Drive Serial Number- VB.NET

Visual Basic 2008 / 2010 / 2012 / 2013

The following tutorial will discuss how to get the harddrive serial number in vb.net. The serial number retrived in the example below is the physical harddrive serial number.

Get Hard Drive Serial Number- vb.net

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim hd As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
        For Each dvs As ManagementObject In hd.Get()
            Dim serial As String = dvs("SerialNumber").ToString()
            TextBox1.Text = serial
End Sub

The above code is tried when one hard drive is installed.