WMI query not working

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am trying to query WMI to get the current IP address of the computer. I have the following code, which queries the MAC address, and this works fine. But if I change the query to "ipaddress" (a valid property), I get a run-time error, something
about a type mismatch. Here is the code that works:
<pre lang="x-vbnet Imports System.Diagnostics
Imports System.Management
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
txtOutput.Clear()
Try
Dim searcher As New ManagementObjectSearcher( _
"rootCIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration")
For Each queryObj As ManagementObject In searcher.Get()
txtOutput.Text = txtOutput.Text + ("MAC Address: " & queryObj("macaddress")) & vbCrLf
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Sub

End Class[/code]

<div style="background-color:white; color:black
<pre>One thing I do find is when I run the same command in Powershell it works fine, but the properties that fail in VB are displayed in curly braces in the Powershell output. [/code]

That is the pattern: All the commands where the output from Powershell is in curly braces fail when run in this VB code. Other properties run correctly with the VB code, like "caption".
Any ideas?
<br/>
<br/>

View the full article
 
Back
Top