Reputation: 107
Respected Sir, How to get the first available motherboards' serial number in this script ?
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
Yours faithfully
Murulimadhav
Upvotes: 0
Views: 5358
Reputation: 54532
I would use the appropriate .Net classes in the System.Management
Namespace they will return a ManagmentObjectCollection
that you can use an index on to return the first instance. Unfortunately with the nature of this class you still need to use late binding which will keep you from turning on Option Strict
. You will need to add the System Management
Namespace to your project references and also import it into your class.
Imports System.Management
Public Class Form1
Public Sub New()
InitializeComponent()
TextBox1.Text = SystemSerialNumber()
End Sub
Private Function SystemSerialNumber() As String
Dim value As String = ""
Dim baseBoard As ManagementClass = New ManagementClass("Win32_BaseBoard")
Dim board As ManagementObjectCollection = baseBoard.GetInstances()
If board.Count > 0 Then
value = board(0)("SerialNumber")
If value.Length > 0 Then value = value.Substring(2)
End If
Return value
End Function
End Class
Upvotes: 3