VB.NET can call HardwareID.dll with Declare statements. The pattern is the same as the C# example: set the license key, allocate a buffer, read the ID.

This example is suitable for WinForms, console and service applications.

Before you start

  1. Install the trial build.
  2. Add the Declare statements to a module.
  3. Call SetLicenseKey() before reading the ID.
  4. Display or transmit the returned string.

Complete example

VB.NET
Public Class Form1
    Public Declare Sub SetLicenseKey Lib "HardwareID.dll" (ByVal LicenseKey As String)
    Public Declare Sub SetAppName Lib "HardwareID.dll" (ByVal AppName As String)
    Public Declare Function GetHardwareId Lib "HardwareID.dll" (ByVal HDD As Boolean, ByVal NIC As Boolean, ByVal CPU As Boolean, ByVal BIOS As Boolean, ByVal lpHWID As String, ByVal nMaxCount As Integer) As Integer
    Public Declare Function IsInsideVMWare Lib "HardwareID.dll" () As Boolean
    Public Declare Function IsInsideVirtualPC Lib "HardwareID.dll" () As Boolean

    Public Sub New()
        InitializeComponent()
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        Dim iRetVal As Long
        Dim lpHWID As String

        If (Not cb_HDD.Checked) And (Not cb_NIC.Checked) And (Not cb_CPU.Checked) And (Not cb_BIOS.Checked) Then
            textBox1.Text = ""
            Exit Sub
        End If

        SetAppName("")

        lpHWID = Space(255)

        iRetVal = GetHardwareId(cb_HDD.Checked, cb_NIC.Checked, cb_CPU.Checked, cb_BIOS.Checked, lpHWID, 255)

        textBox1.Text = lpHWID

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim iRetVal As Long
        Dim lpHWID As String

        If (Not cb_HDD.Checked) And (Not cb_NIC.Checked) And (Not cb_CPU.Checked) And (Not cb_BIOS.Checked) Then
            textBox1.Text = ""
            Exit Sub
        End If

        SetAppName(TextBox2.Text)

        lpHWID = Space(255)

        iRetVal = GetHardwareId(cb_HDD.Checked, cb_NIC.Checked, cb_CPU.Checked, cb_BIOS.Checked, lpHWID, 255)

        TextBox3.Text = lpHWID
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetLicenseKey("Your-License-Key")

        If IsInsideVMWare() Then
            LabVmware.Text = "Yes"
        End If

        If IsInsideVirtualPC() Then
            LabVirtualPC.Text = "Yes"
        End If
    End Sub
End Class

How it works

  • Match the project's platform target to the DLL bitness.
  • Use StringBuilder for the output buffer.
  • Test on a clean machine to confirm the ID remains stable.
During evaluation, leave the placeholder license key in place. After purchase, replace it with the key from your email.