Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet mother board serial numbers and CPU IDs in Visual Basic .NET
DescriptionThis example shows how to use WMI to get mother board serial numbers and CPU IDs in Visual Basic .NET.
Keywordsserial number, cpu, cpu id, WMI, Windows Management Instrumentation, Visual Basic .NET, VB.NET
CategoriesSoftware 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
    ' Get the Windows Management Instrumentation object.
    Dim wmi As Object = GetObject("WinMgmts:")

    ' Get the "base boards" (mother boards).
    Dim serial_numbers As String = ""
    Dim mother_boards As Object = _
        wmi.InstancesOf("Win32_BaseBoard")
    For Each board As Object In mother_boards
        serial_numbers &= ", " & board.SerialNumber
    Next board
    If serial_numbers.Length > 0 Then serial_numbers = _
        serial_numbers.Substring(2)

    Return 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 Object = GetObject("winmgmts:" & _
        "{impersonationLevel=impersonate}!\\" & _
        computer & "\root\cimv2")
    Dim processors As Object = wmi.ExecQuery("Select * from " & _
        "Win32_Processor")

    Dim cpu_ids As String = ""
    For Each cpu As Object In processors
        cpu_ids = cpu_ids & ", " & cpu.ProcessorId
    Next cpu
    If cpu_ids.Length > 0 Then cpu_ids = _
        cpu_ids.Substring(2)
 
    Return cpu_ids
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated