Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

Setting DNS Search Suffix order from VB.NET

Is there any way to do this:

<code start>
 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set objNetworkSettings =  objWMIService.Get("Win32_NetworkAdapterConfiguration")

intSetSuffixes =  objNetworkSettings.SetDNSSuffixSearchOrder(arrNewDNSSuffixSearchOrder)

<code finish>

Directly from VB.NET rather then having to resort to VBScript?

Many thanks!






0
dcx45
Asked:
dcx45
1 Solution
 
heintalusCommented:
Yes you'll need to use the ManagementObject class which is the .Net way of using WMI

for example to read settings from WMI you could use something like this, which you can adapt to set the value

GetDetails("win32_networkadapterconfiguration", "DNSServerSearchOrder", _DNSSearchOrder)

Private Sub GetDetails(ByVal ClassName As String, ByVal Selection As String, ByRef Prop As String)
        Dim tmpstr As String = ""

        Try
            Dim myScope As New ManagementScope("\\" & _Computer & "\root\cimv2")
            Dim oQuery As New SelectQuery("SELECT " & Selection & " FROM " & ClassName & " WHERE index='" & _Instance & "'")
            Dim oResults As New ManagementObjectSearcher(myScope, oQuery)
            Dim oItem As ManagementObject
            Dim oProperty As PropertyData

            For Each oItem In oResults.Get()
                For Each oProperty In oItem.Properties
                    If oProperty.IsArray Then
                        tmpstr = GetArrayDetails(CType(oProperty.Value, String()))
                    Else
                        tmpstr = oProperty.Value.ToString
                    End If
                Next
            Next

            Try
                oResults.Dispose()
                oItem.Dispose()
            Catch ex As Exception
            End Try

            myScope = Nothing
            oQuery = Nothing
            oResults = Nothing
            oItem = Nothing
            oProperty = Nothing
        Catch ex As Exception
        End Try

        If Not tmpstr = Prop Then
            Prop = tmpstr
        End If

        tmpstr = Nothing
    End Sub

    Private Function GetArrayDetails(ByVal PropVal() As String) As String
        Dim tmpbldr As New StringBuilder

        Dim x As Integer
        For x = 0 To PropVal.GetUpperBound(0)
            tmpbldr.Append(PropVal(x) & " ")
        Next
        Return tmpbldr.ToString
    End Function

HTH
Andy
0
 
dcx45Author Commented:
Thanks Andy, this shed's a light on how to use WMI from VB. Thanks a lot.

Rad
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now