Getting Hardware Information Using Visual Basic.NET and VBScript (Page 1 of 4 )
This article explains how to retrieve hardware information using both Visual Basic.NET and VBScript. We shall cover motherboards, on board devices and processors.
A downloadable file for this story is available
here.
The sample downloadable solution (zip) was entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that it would work with other versions of Windows (which support .NET 1.1) versions as well.
I contributed several articles covering WMI with VB.NET and VBScript, including the articles on introductory or basic topics concerning WMI. I even contributed a series of about six articles on “WMI Programming on VB.NET” covering several aspects of WMI. I strongly suggest you go through the series, before going through this article.
Listing the “On Board Devices” available
Some scenarios may require some properties of the onboard devices of the motherboard to be listed. Instead of opening the CPU and going through each and every device, we can retrieve the same information dynamically using VB.NET. The following VB.NET code should support retrieving some minimum information about devices 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_OnBoardDevice")
Dim dt As DataTable = globals.getOnBoardDeviceStructure
For Each queryObj As ManagementObject In searcher.Get()
globals.addOnBoardDevice(dt, queryObj("Description"), Convert.ToString(queryObj("DeviceType")), queryObj("Enabled"), queryObj("Tag"))
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_OnBoardDevice",,48)
For Each objItem in colItems
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceType: " & objItem.DeviceType
Wscript.Echo "Enabled: " & objItem.Enabled
Wscript.Echo "Tag: " & objItem.Tag
Next
Next: The class Win32 OnBoardDevice in detail >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee