Getting Hardware Information using Visual Basic.NET and VBScript continued - Listing the “Sound Device” information
(Page 5 of 5 )
The following code displays information about the audio device installed on your computer. Before trying to retrieve the hardware information, let us create the wrapper with “SoundDevice” structure:
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
The following method “addSoundDevice” adds single row based on the structure you create for the data table using the above method.
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
Once you complete the creation of wrapper, the following VB.NET code should support with some minimum information about the sound device 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_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.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_SoundDevice",,48)
For Each objItem in colItems
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Wscript.Echo "ProductName: " & objItem.ProductName
Next
Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |