This is a continuation of my other tutorial entitled Display Bios Information using VB.NET, but this time it will display all the hardware information such as Bus,Motherboard,Memory, and Sound in Vb.NET also.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to
File, click
New Project, and choose
Windows Application.
2. Next, add a TabControl and a DataGridView Only. You must design your interface like this:
3. Now, we will do the coding.
First we will create a vb module named globals.
We will have to create public sub procedure named addRow that will add rows to the DataGridView.
For Sound Device:
Public Function getSoundDeviceStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Manufacturer"))
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("PNPDeviceID"))
dt.Columns.Add(New DataColumn("ProductName"))
Return dt
End Function
Public Sub addSoundDevice(ByRef dt As DataTable, ByVal Manufacturer As String, ByVal Name As String, ByVal PNPDeviceID As String, ByVal ProductName As String)
Dim dr As DataRow
dr = dt.NewRow
dr("Manufacturer") = Manufacturer
dr("Name") = Name
dr("PNPDeviceID") = PNPDeviceID
dr("ProductName") = ProductName
dt.Rows.Add(dr)
End Sub
For memory device:
Public Function getMemoryDeviceStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("DeviceID"))
dt.Columns.Add(New DataColumn("EndingAddress"))
dt.Columns.Add(New DataColumn("StartingAddress"))
dt.Columns.Add(New DataColumn("SystemName"))
Return dt
End Function
Public Sub addMemoryDevice(ByRef dt As DataTable, ByVal DeviceID As String, ByVal EndingAddress As String, ByVal StartingAddress As String, ByVal SystemName As String)
Dim dr As DataRow
dr = dt.NewRow
dr("DeviceID") = DeviceID
dr("EndingAddress") = EndingAddress
dr("StartingAddress") = StartingAddress
dr("SystemName") = SystemName
dt.Rows.Add(dr)
End Sub
For motherboard device:
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
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
For bus device:
Public Function getBusStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("BusType"))
dt.Columns.Add(New DataColumn("DeviceID"))
dt.Columns.Add(New DataColumn("PNPDeviceID"))
dt.Columns.Add(New DataColumn("SystemName"))
Return dt
End Function
Public Sub addBus(ByRef dt As DataTable, ByVal BusType As String, ByVal DeviceID As String, ByVal PNPDeviceID As String, ByVal SystemName As String)
Dim dr As DataRow
dr = dt.NewRow
dr("BusType") = BusType
dr("DeviceID") = DeviceID
dr("PNPDeviceID") = PNPDeviceID
dr("SystemName") = SystemName
dt.Rows.Add(dr)
End Sub
4. Then we will do the coding for the form_load.
For displaying the Bus Device:
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_Bus")
Dim dt As DataTable = globals.getBusStructure
For Each queryObj As ManagementObject In searcher.Get()
globals.addBus(dt, Convert.ToString(queryObj("BusType")), queryObj("DeviceID"), queryObj("PNPDeviceID"), queryObj("SystemName"))
Next
Me.DataGridView2.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
For displaying the Motherboard Device:
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.DataGridView3.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
For displaying the Memory Device:
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_MemoryDevice")
Dim dt As DataTable = globals.getMemoryDeviceStructure
For Each queryObj As ManagementObject In searcher.Get()
globals.addMemoryDevice(dt, queryObj("DeviceID"), Convert.ToString(queryObj("EndingAddress")), Convert.ToString(queryObj("StartingAddress")), queryObj("SystemName"))
Next
Me.DataGridView4.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
For displaying the Sound Device:
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_SoundDevice")
Dim dt As DataTable = globals.getSoundDeviceStructure
For Each queryObj As ManagementObject In searcher.Get()
globals.addSoundDevice(dt, queryObj("Manufacturer"), queryObj("Name"), queryObj("PNPDeviceID"), queryObj("ProductName"))
Next
Me.DataGridView5.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
Output:
Download the source code and try it.
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware