Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting DNS Search Suffix order from VB.NET

Posted on 2004-10-07
2
Medium Priority
?
458 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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