Solved

Setting DNS Search Suffix order from VB.NET

Posted on 2004-10-07
2
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Schema 6 58
VB/ASP.Net "Value of type 'Date' cannot be converted to 'Integer'" 12 60
Asp.Net Session Question 2 49
Help with viewing image in ReportViewer 14 32
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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