Display Hardware Information (Bus,Motherboard,Memory,Sound) in Vb.NET

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: output 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:
  1. Public Function getSoundDeviceStructure() As DataTable
  2. Dim dt As New DataTable
  3. dt.Columns.Add(New DataColumn("Manufacturer"))
  4. dt.Columns.Add(New DataColumn("Name"))
  5. dt.Columns.Add(New DataColumn("PNPDeviceID"))
  6. dt.Columns.Add(New DataColumn("ProductName"))
  7. Return dt
  8. End Function
  9. Public Sub addSoundDevice(ByRef dt As DataTable, ByVal Manufacturer As String, ByVal Name As String, ByVal PNPDeviceID As String, ByVal ProductName As String)
  10. Dim dr As DataRow
  11. dr = dt.NewRow
  12. dr("Manufacturer") = Manufacturer
  13. dr("Name") = Name
  14. dr("PNPDeviceID") = PNPDeviceID
  15. dr("ProductName") = ProductName
  16. dt.Rows.Add(dr)
  17. End Sub
For memory device:
  1. Public Function getMemoryDeviceStructure() As DataTable
  2. Dim dt As New DataTable
  3. dt.Columns.Add(New DataColumn("DeviceID"))
  4. dt.Columns.Add(New DataColumn("EndingAddress"))
  5. dt.Columns.Add(New DataColumn("StartingAddress"))
  6. dt.Columns.Add(New DataColumn("SystemName"))
  7. Return dt
  8. End Function
  9. Public Sub addMemoryDevice(ByRef dt As DataTable, ByVal DeviceID As String, ByVal EndingAddress As String, ByVal StartingAddress As String, ByVal SystemName As String)
  10. Dim dr As DataRow
  11. dr = dt.NewRow
  12. dr("DeviceID") = DeviceID
  13. dr("EndingAddress") = EndingAddress
  14. dr("StartingAddress") = StartingAddress
  15. dr("SystemName") = SystemName
  16. dt.Rows.Add(dr)
  17. End Sub
For motherboard device:
  1. Public Function getMotherBoardDevice() As DataTable
  2. Dim dt As New DataTable
  3. dt.Columns.Add(New DataColumn("DeviceID"))
  4. dt.Columns.Add(New DataColumn("PrimaryBusType"))
  5. dt.Columns.Add(New DataColumn("SecondaryBusType"))
  6. Return dt
  7. End Function
  8. Public Sub addMotherBoardDevice(ByRef dt As DataTable, ByVal DeviceID As String, ByVal PrimaryBusType As String, ByVal SecondaryBusType As String)
  9. Dim dr As DataRow
  10. dr = dt.NewRow
  11. dr("DeviceID") = DeviceID
  12. dr("PrimaryBusType") = PrimaryBusType
  13. dr("SecondaryBusType") = SecondaryBusType
  14. dt.Rows.Add(dr)
  15. End Sub
For bus device:
  1. Public Function getBusStructure() As DataTable
  2. Dim dt As New DataTable
  3. dt.Columns.Add(New DataColumn("BusType"))
  4. dt.Columns.Add(New DataColumn("DeviceID"))
  5. dt.Columns.Add(New DataColumn("PNPDeviceID"))
  6. dt.Columns.Add(New DataColumn("SystemName"))
  7. Return dt
  8. End Function
  9. Public Sub addBus(ByRef dt As DataTable, ByVal BusType As String, ByVal DeviceID As String, ByVal PNPDeviceID As String, ByVal SystemName As String)
  10. Dim dr As DataRow
  11. dr = dt.NewRow
  12. dr("BusType") = BusType
  13. dr("DeviceID") = DeviceID
  14. dr("PNPDeviceID") = PNPDeviceID
  15. dr("SystemName") = SystemName
  16. dt.Rows.Add(dr)
  17. End Sub
4. Then we will do the coding for the form_load. For displaying the Bus Device:
  1. Try
  2. Dim searcher As New ManagementObjectSearcher( _
  3. "root\CIMV2", _
  4. "SELECT * FROM Win32_Bus")
  5. Dim dt As DataTable = globals.getBusStructure
  6. For Each queryObj As ManagementObject In searcher.Get()
  7. globals.addBus(dt, Convert.ToString(queryObj("BusType")), queryObj("DeviceID"), queryObj("PNPDeviceID"), queryObj("SystemName"))
  8. Next
  9. Me.DataGridView2.DataSource = dt
  10. Catch err As ManagementException
  11. MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
  12. End Try
For displaying the Motherboard Device:
  1. Try
  2. Dim searcher As New ManagementObjectSearcher( _
  3. "root\CIMV2", _
  4. "SELECT * FROM Win32_MotherboardDevice")
  5.  
  6. Dim dt As DataTable = globals.getMotherBoardDevice
  7. For Each queryObj As ManagementObject In searcher.Get()
  8. globals.addMotherBoardDevice(dt, queryObj("DeviceID"), queryObj("PrimaryBusType"), queryObj("SecondaryBusType"))
  9. Next
  10. Me.DataGridView3.DataSource = dt
  11. Catch err As ManagementException
  12. MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
  13. End Try
For displaying the Memory Device:
  1. Try
  2. Dim searcher As New ManagementObjectSearcher( _
  3. "root\CIMV2", _
  4. "SELECT * FROM Win32_MemoryDevice")
  5.  
  6. Dim dt As DataTable = globals.getMemoryDeviceStructure
  7. For Each queryObj As ManagementObject In searcher.Get()
  8. globals.addMemoryDevice(dt, queryObj("DeviceID"), Convert.ToString(queryObj("EndingAddress")), Convert.ToString(queryObj("StartingAddress")), queryObj("SystemName"))
  9. Next
  10. Me.DataGridView4.DataSource = dt
  11. Catch err As ManagementException
  12. MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
  13. End Try
For displaying the Sound Device:
  1. Try
  2. Dim searcher As New ManagementObjectSearcher( _
  3. "root\CIMV2", _
  4. "SELECT * FROM Win32_SoundDevice")
  5.  
  6. Dim dt As DataTable = globals.getSoundDeviceStructure
  7. For Each queryObj As ManagementObject In searcher.Get()
  8. globals.addSoundDevice(dt, queryObj("Manufacturer"), queryObj("Name"), queryObj("PNPDeviceID"), queryObj("ProductName"))
  9. Next
  10. Me.DataGridView5.DataSource = dt
  11. Catch err As ManagementException
  12. MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
  13. End Try

Output:

outputoutputoutputoutput 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

Add new comment