Connecting Tech Pros Worldwide Help | Site Map

VB.Net and Win32_NetworkAdapterConfiguration

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 28th, 2008, 03:55 PM
=?Utf-8?B?d2hpZ2dpbnNAbm9lbWFpbC5ub2VtYWls?=
Guest
 
Posts: n/a
Default VB.Net and Win32_NetworkAdapterConfiguration

Hello

I used Code Creator to generate the below vb.net code to pull some
information using the management namespace. I only posted a small section of
the code but it will represent the problem I am having.

I am using Dot Net
Framework version 2.0 and the bleow code generates an error.

This section causes the error
Dim arrDNSDomainSuffixSearchOrder As String()
arrDNSDomainSuffixSearchOrder = queryObj("DNSDomainSuffixSearchOrder")

The error message states: Value of type 'String' cannot be converted to
'1-dimensional array of String'

I am a bit new to coding in windows environment so any help would be greatly
appreciated.

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

Public Class MyWMIQuery

Public Overloads Shared Function Main() As Integer

Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration")

For Each queryObj As ManagementObject in searcher.Get()

Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_NetworkAdapterConfigurati on
instance")
Console.WriteLine("-----------------------------------")

If queryObj("DNSDomainSuffixSearchOrder") Is Nothing Then
Console.WriteLine("DNSDomainSuffixSearchOrder: {0}",
queryObj("DNSDomainSuffixSearchOrder"))
Else
Dim arrDNSDomainSuffixSearchOrder As String()
arrDNSDomainSuffixSearchOrder =
queryObj("DNSDomainSuffixSearchOrder")
For Each arrValue As String In
arrDNSDomainSuffixSearchOrder
Console.WriteLine("DNSDomainSuffixSearchOrder:
{0}", arrValue)
Next
End If
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI
data: " & err.Message)
End Try
End Function
End Class
End Namespace

  #2  
Old September 3rd, 2008, 05:15 AM
=?Utf-8?B?d2hpZ2dpbnM=?=
Guest
 
Posts: n/a
Default RE: VB.Net and Win32_NetworkAdapterConfiguration

I found the solution to the problem kind of. I had to turn Option Strict of.
I wrote a function that returns a string.

Dim strBuilder = appendCollection(queryObj("DNSDomainSuffixSearchOr der"))

Private Function appendCollection(ByVal coll As Array) As String
Dim str As String = ""
Dim strBuilder As String = ""
For Each str In coll
If strBuilder = "" Then
strBuilder = str
Else
strBuilder = strBuilder & "," & str
End If
Next
Return strBuilder
End Function

"whiggins@noemail.noemail" wrote:
Quote:
Hello
>
I used Code Creator to generate the below vb.net code to pull some
information using the management namespace. I only posted a small section of
the code but it will represent the problem I am having.
>
I am using Dot Net
Framework version 2.0 and the bleow code generates an error.
>
This section causes the error
Dim arrDNSDomainSuffixSearchOrder As String()
arrDNSDomainSuffixSearchOrder = queryObj("DNSDomainSuffixSearchOrder")
>
The error message states: Value of type 'String' cannot be converted to
'1-dimensional array of String'
>
I am a bit new to coding in windows environment so any help would be greatly
appreciated.
>
Imports System
Imports System.Management
Imports System.Windows.Forms
>
Namespace WMISample
>
Public Class MyWMIQuery
>
Public Overloads Shared Function Main() As Integer
>
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration")
>
For Each queryObj As ManagementObject in searcher.Get()
>
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_NetworkAdapterConfigurati on
instance")
Console.WriteLine("-----------------------------------")
>
If queryObj("DNSDomainSuffixSearchOrder") Is Nothing Then
Console.WriteLine("DNSDomainSuffixSearchOrder: {0}",
queryObj("DNSDomainSuffixSearchOrder"))
Else
Dim arrDNSDomainSuffixSearchOrder As String()
arrDNSDomainSuffixSearchOrder =
queryObj("DNSDomainSuffixSearchOrder")
For Each arrValue As String In
arrDNSDomainSuffixSearchOrder
Console.WriteLine("DNSDomainSuffixSearchOrder:
{0}", arrValue)
Next
End If
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI
data: " & err.Message)
End Try
End Function
End Class
End Namespace
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.