Solved

Setting DNS Search Suffix order from VB.NET

Posted on 2004-10-07
2
404 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
Comment Utility
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
Comment Utility
Thanks Andy, this shed's a light on how to use WMI from VB. Thanks a lot.

Rad
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now