|
|
Title | Get mother board serial numbers and CPU IDs in Visual Basic 6 |
Description | This example shows how to use WMI to get mother board serial numbers and CPU IDs in Visual Basic 6. |
Keywords | serial number, cpu, cpu id, WMI, Windows Management Instrumentation, Visual Basic 6 |
Categories | Software Engineering, Windows, Miscellany |
|
|
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
|
|
|
|
|
|