Getting Hardware Information using Visual Basic.NET and VBScript continued - Listing the “MotherBoard” information
(Page 3 of 5 )
My previous article already listed some “On Board Devices” and also some information abou the “Base Board.” This section works as an extension to both of them. Basically, we are going to try to retrieve the “PrimaryBusType”, “SecondaryBusType” and “DeviceID” of the available “MotherBoard.” Before trying to retrieve the hardware information, let us create the wrapper with “MotherBoard” structure:
Public Function getMotherBoardDevice() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("DeviceID"))
dt.Columns.Add(New DataColumn("PrimaryBusType"))
dt.Columns.Add(New DataColumn("SecondaryBusType"))
Return dt
End Function
The following method “addMotherBoardDevice” adds a single row based on the structure you create for the data table using the above method.
Public Sub addMotherBoardDevice(ByRef dt As DataTable, ByVal DeviceID As String, ByVal PrimaryBusType As String, ByVal SecondaryBusType As String)
Dim dr As DataRow
dr = dt.NewRow
dr("DeviceID") = DeviceID
dr("PrimaryBusType") = PrimaryBusType
dr("SecondaryBusType") = SecondaryBusType
dt.Rows.Add(dr)
End Sub
Once you complete the creation of wrapper, the following VB.NET code should support retrieving some minimum information about the motherboard available on your system.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_MotherboardDevice")
Dim dt As DataTable = globals.getMotherBoardDevice
For Each queryObj As ManagementObject In searcher.Get
()
globals.addMotherBoardDevice(dt, queryObj("DeviceID"), queryObj
("PrimaryBusType"), queryObj("SecondaryBusType"))
Next
Me.DataGrid1.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for
WMI data: " & err.Message)
End Try
End Sub
You can achieve the same thing with VBScript as follows:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_MotherboardDevice",,48)
For Each objItem in colItems
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "PrimaryBusType: " & objItem.PrimaryBusType
Wscript.Echo "SecondaryBusType: " & objItem.SecondaryBusType
Next
Next: Listing the Memory information >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee