Source code example for using HDDPhysic component to get hard disk physical info (like the unique hdd serial number) with VB.NET 2005 is now available in the resources area of the product (here).
Here are some few steps on how you should use it in VB.NET:
(1) Declare imported library functions:
HDiskInfo.vb :
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Module HDiskInfo
Public Declare Function Init Lib "HDDPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Integer
Public Declare Function GetPhysicInfo Lib "HDDPhysic.dll" (ByVal diskIndex As Short, ByVal InfoType As Integer, ByVal pHddInfo As String) As Integer
End Module
Option Explicit On
Imports System.Runtime.InteropServices
Module HDiskInfo
Public Declare Function Init Lib "HDDPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Integer
Public Declare Function GetPhysicInfo Lib "HDDPhysic.dll" (ByVal diskIndex As Short, ByVal InfoType As Integer, ByVal pHddInfo As String) As Integer
End Module
(2) Call the Init function to initialize the user computer hard drives and get the total available devices:
Form1.vb :
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim tDiscs As Integer
Dim intX As Short
Dim WinHdd As Short
tDiscs = Init("your reg code here", "your reg code here")
If tDiscs > 0 Then
For intX = 0 To tDiscs - 1
Me.Combo1.Items.Add(intX) 'populate combo with hdd indexes
Next
WinHdd = GetPhysicInfo(0, 6, "") 'get windows hdd index
If WinHdd >= 0 Then
edtDrive.Text = WinHdd 'windows is installed on this drive index
Combo1.SelectedIndex = WinHdd
End If
End If
End Sub
Dim tDiscs As Integer
Dim intX As Short
Dim WinHdd As Short
tDiscs = Init("your reg code here", "your reg code here")
If tDiscs > 0 Then
For intX = 0 To tDiscs - 1
Me.Combo1.Items.Add(intX) 'populate combo with hdd indexes
Next
WinHdd = GetPhysicInfo(0, 6, "") 'get windows hdd index
If WinHdd >= 0 Then
edtDrive.Text = WinHdd 'windows is installed on this drive index
Combo1.SelectedIndex = WinHdd
End If
End If
End Sub
(3) Now that you have the total hard drives count you can query for the manufacturer information passing the disk index to the GetPhysicInfo function:
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim iDiskNo As Integer
Dim sBuffer As String
Dim iReturn As Integer
sBuffer = Space(1024) ' make room in the buffer
iDiskNo = Combo1.SelectedIndex 'get selected disk number
ClearEdit() 'clear previous values
iReturn = GetPhysicInfo(iDiskNo, 0, sBuffer) '0 = serial number
Text1.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 1, sBuffer) '1 = hdd model
Text2.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 2, sBuffer) '2 = hdd revision
Text3.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 3, sBuffer) '3 = hdd type
Text7.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 4, sBuffer) '4 = hdd size
Text5.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 5, sBuffer) '5 = hdd buffer size
Text4.Text = Strings.Left(sBuffer, iReturn)
End Sub
Dim iDiskNo As Integer
Dim sBuffer As String
Dim iReturn As Integer
sBuffer = Space(1024) ' make room in the buffer
iDiskNo = Combo1.SelectedIndex 'get selected disk number
ClearEdit() 'clear previous values
iReturn = GetPhysicInfo(iDiskNo, 0, sBuffer) '0 = serial number
Text1.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 1, sBuffer) '1 = hdd model
Text2.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 2, sBuffer) '2 = hdd revision
Text3.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 3, sBuffer) '3 = hdd type
Text7.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 4, sBuffer) '4 = hdd size
Text5.Text = Strings.Left(sBuffer, iReturn)
iReturn = GetPhysicInfo(iDiskNo, 5, sBuffer) '5 = hdd buffer size
Text4.Text = Strings.Left(sBuffer, iReturn)
End Sub