Solved

Setting DNS Search Suffix order from VB.NET

Posted on 2004-10-07
2
423 Views
Last Modified: 2008-02-01
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
Comment
Question by:dcx45
2 Comments
 
LVL 10

Accepted Solution

by:
heintalus earned 500 total points
ID: 12252806
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
 

Author Comment

by:dcx45
ID: 12285769
Thanks Andy, this shed's a light on how to use WMI from VB. Thanks a lot.

Rad
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question