Hi,
How can I do to get motherboard and processor serial number in VB6?
I am able to get HD serial number with this code:

Option Explicit
Private Type DRIVEINFO
    HDDSerialNum As String
End Type
Private Sub Form_Load()
Dim info As DRIVEINFO
Dim objs As Object
Dim obj As Object
Dim WMI As Object
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.instancesof("Win32_PhysicalMedia")
For Each obj In objs
    info.HDDSerialNum = obj.serialnumber
Next obj
End Sub

Can you help me?
Thank.

Dani AI

Generated

: your HD approach and : the WMI-based baseboard/CPU idea are the right direction — WMI exposes the motherboard serial and processor identifier through the system classes, but there are important reliability and permission caveats to understand.

WMI classes to try (and to use as fallbacks) include the baseboard, BIOS and product classes; these properties come from SMBIOS and can be empty or contain vendor placeholders. See the official class references for details: Win32_BaseBoard and Win32_Processor. If a property is missing, also check Win32_BIOS and Win32_ComputerSystemProduct as alternative SMBIOS sources.

Troubleshooting tips: verify results interactively with wbemtest / WMIC / PowerShell to confirm whether the value is supplied by the system or it’s your code. WMI security/impersonation can affect returned data — use the impersonation level recommended for scripts when needed. See Microsoft notes on impersonation and connecting to WMI. (ImpersonationLevel docs)

Hard-drive serials via Win32_PhysicalMedia are optional (default NULL) and sometimes inconsistent across drivers or in virtualized/RAID/NVMe setups; this is a common WMI limitation (reports and examples on this are on community Q&A). If you need a robust manufacturer serial, query the device descriptor via DeviceIoControl (IOCTL_STORAGE_QUERY_PROPERTY / STORAGE_DEVICE_DESCRIPTOR) or use vendor/SMART utilities — Microsoft docs describe the storage descriptor layout and SerialNumberOffset. (Win32_PhysicalMedia, STORAGE_DEVICE_DESCRIPTOR, see community notes on WMI quirks.)

Practical cautions: always handle Nulls, trim whitespace and vendor filler text (eg. "To be filled by OEM"), test on real hardware vs VM, and combine multiple hardware fields if you need a more stable identifier (don’t rely on a single WMI field for critical licensing or security).

Recommended Answers

All 3 Replies

The following function gets a WMI object and then gets a collection of WMI_BaseBoard objects representing the system's mother boards. It loops through them getting their serial numbers.

Private Function SystemSerialNumber() As String
Dim mother_boards As Variant
Dim board As Variant
Dim wmi As Variant
Dim serial_numbers As String

    ' Get the Windows Management Instrumentation object.
    Set wmi = GetObject("WinMgmts:")

    ' Get the "base boards" (mother boards).
    Set mother_boards = wmi.InstancesOf("Win32_BaseBoard")
    For Each board In mother_boards
        serial_numbers = serial_numbers & ", " & _
            board.SerialNumber
    Next board
    If Len(serial_numbers) > 0 Then serial_numbers = _
        Mid$(serial_numbers, 3)

    SystemSerialNumber = serial_numbers
End Function

The following code gets a WMI object and selects Win32_Processor objects. It loops through them getting their processor IDs.

Private Function CpuId() As String
Dim computer As String
Dim wmi As Variant
Dim processors As Variant
Dim cpu As Variant
Dim cpu_ids As String

    computer = "."
    Set wmi = GetObject("winmgmts:" & _
        "{impersonationLevel=impersonate}!\\" & _
        computer & "\root\cimv2")
    Set processors = wmi.ExecQuery("Select * from " & _
        "Win32_Processor")

    For Each cpu In processors
        cpu_ids = cpu_ids & ", " & cpu.ProcessorId
    Next cpu
    If Len(cpu_ids) > 0 Then cpu_ids = Mid$(cpu_ids, 3)

    CpuId = cpu_ids
End Function

PERFECT! Thank you very much!!!

Only a pleasure. Happy coding...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.