Vb.net 使用WMI获取网络适配器信息
我正在尝试从远程服务器检索网络适配器配置详细信息。我在VB.NET中使用WMI生成了以下代码 当代码被执行时(点击按钮),我得到一个错误 “查询WMI数据时出错:未找到” 请帮助我对这段代码哪里出了问题提出任何建议或更正Vb.net 使用WMI获取网络适配器信息,vb.net,wmi,Vb.net,Wmi,我正在尝试从远程服务器检索网络适配器配置详细信息。我在VB.NET中使用WMI生成了以下代码 当代码被执行时(点击按钮),我得到一个错误 “查询WMI数据时出错:未找到” 请帮助我对这段代码哪里出了问题提出任何建议或更正 Try Dim path As ManagementPath = Nothing Dim options As ConnectionOptions = Nothing Dim scope As ManagementScop
Try
Dim path As ManagementPath = Nothing
Dim options As ConnectionOptions = Nothing
Dim scope As ManagementScope = Nothing
path = New ManagementPath("\\" & ServerName & "\root\cimv2")
options = New ConnectionOptions
options.Username = usernamebox.Text
options.Password = passwordbox.Text
scope = New ManagementScope(path, options)
scope.Connect()
Try
If scope.IsConnected = True Then
Dim nwquery As ObjectQuery = Nothing
nwquery = New ObjectQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(scope, nwquery)
Dim nwquerycol As ManagementObjectCollection
nwquerycol = searcher.Get
For Each nwobject As ManagementObject In nwquerycol
DataView_TextBox.Text &= "Name: " + nwobject("Name") & Newline
DataView_TextBox.Text &= "Name: " + nwobject("Description") & Newline
DataView_TextBox.Text &= "DHCPEnabled: " + (nwobject("DHCPEnabled").ToString) & ControlChars.NewLine
DataView_TextBox.Text &= "DHCPServer: " + nwobject("DHCPServer") & ControlChars.NewLine
DataView_TextBox.Text &= "DNSDomain: " + nwobject("DNSDomain") & ControlChars.NewLine
DataView_TextBox.Text &= "DNSHostName: " + nwobject("DNSHostName") & ControlChars.NewLine
If nwobject("IPAddress") Is Nothing Then
DataView_TextBox.Text &= "IPAddress:" + nwobject("IPAddress") & ControlChars.NewLine
Else
Dim arrIPAddress As String
arrIPAddress = nwobject("IPAddress")
For Each arrValue As String In arrIPAddress
DataView_TextBox.Text &= "IPAddress: {0}" + arrValue & ControlChars.NewLine
Next
End If
If nwobject("IPSubnet") Is Nothing Then
DataView_TextBox.Text &= "IPSubnet: " + nwobject("IPSubnet") & ControlChars.NewLine
Else
Dim arrIPSubnet As String
arrIPSubnet = nwobject("IPSubnet")
For Each arrValue As String In arrIPSubnet
DataView_TextBox.Text &= "IPSubnet: {0}" + arrValue & ControlChars.NewLine
Next
End If
DataView_TextBox.Text &= "MACAddress: {0}" + nwobject("MACAddress") & ControlChars.NewLine
DataView_TextBox.Text &= "======================================" & ControlChars.NewLine
Next
End If
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & ex.Message)
End Try
Catch ex As Exception
MessageBox.Show("An error occurred while querying for WMI data: " & ex.Message)
End Try
wmic path Win32\u networkadapter配置获取标题,ipenabled
命令的输出是什么?该命令成功列出了我试图通过程序查询的远程计算机上的所有网络适配器标题和ipenabled状态(真/假)。首先,您应该打开选项Strict
。并不是您试图获取的所有属性都是为该类定义的;看见显示如何转储输出窗口中可用的内容