Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:36:18+00:00 2026-05-22T22:36:18+00:00

I’m a beginner in programming. I wrote a script to set DNS setting using

  • 0

I’m a beginner in programming. I wrote a script to set DNS setting using VB. I was able to set the primary address.

However, I don’t know how to set the secondary address because it will require the use of array.

How can this be done?

Dim DNS As String() = {"192.168.1.1", "192.168.1.2"}

Dim objMC As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim objMOC As ManagementObjectCollection = objMC.GetInstances()

For Each objMO As ManagementObject In objMOC
    If (Not CBool(objMO("IPEnabled"))) Then
        Continue For
    End If

    Try
        Dim objSetIP As ManagementBaseObject = Nothing
        Dim objNewDNS As ManagementBaseObject = Nothing
        objNewDNS = objMO.GetMethodParameters("SetDNSServerSearchOrder")

        'Set DNS to DHCP
        objNewDNS("DNSServerSearchOrder") = New String() {DNS()}
        objSetIP = objMO.InvokeMethod("SetDNSServerSearchOrder", objNewDNS, Nothing)
        Console.WriteLine("Updated IPAddress, SubnetMask and Default Gateway!")
    Catch ex As Exception
        MessageBox.Show("Unable to Set IP : " & ex.Message)
    End Try
Next objMO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:36:18+00:00Added an answer on May 22, 2026 at 10:36 pm

    In VB.Net the Dim keyword is actually short for Dimension and can be used for declaring arrays.

    Simply apply brackets to the variable or type and hey presto you have an array.

    Dim arrayOfString As String()
    

    Or

    Dim arrayOfString() As String
    

    Of course, its a little more complicated than that. You may want to declare your array with a predefined number of elements, say 5, assuming Option Base 0.

    Dim arrayOfInt(4) As Int
    

    Or you might want to assign your array with a number of predefined values.

    Dim arrayofInt As Int() = {1, 2, 3, 4, 5}
    

    You can also use this syntax,

    Dim arrayOfStrings = New String() {"1.2.3.4", "5.6.7.8"}
    

    for instance. Your example,

    Dim DNS As String() = {"192.168.1.1", "192.168.1.2"} 
    

    seems perfectly valid.

    In your example you have the misforstune to be using WMI. I see you want to invoke the "SetDNSServerSearchOrder" method on the "Win32_NetworkAdapterConfiguration" class.

    The objNewDNS = objMO.GetMethodParameters("SetDNSServerSearchOrder") sets objNewDNS to a ManagementBaseObject that is a collection of parameters for the "SetDNSServerSearchOrder" method.

    The "SetDNSServerSearchOrder" takes one parameter called "DNSServerSearchOrder" as described here which happens to be an array of strings.

    So unless I’m mistaken, and assuming the string array DNS is your search order, your code should read:

    'Set DNS to DHCP         
    objNewDNS("DNSServerSearchOrder") = DNS 
    objMO.InvokeMethod("SetDNSServerSearchOrder", objNewDNS)
    

    note that this code discards the return value of the method call.

    EDIT:

    From your comments it seems that the object returned by the objMO.InvokeMehtod call is actually a ManagementBaseObject. This wraps the “returnValue” of the invoked method. So somthing like the code below will help you get to the return value, if necessary.

    'Set DNS to DHCP         
    objNewDNS("DNSServerSearchOrder") = DNS 
    Dim oResult As ManagementBaseObject = _
        objMO.InvokeMethod("SetDNSServerSearchOrder", objNewDNS)
    Dim result As Integer = CType(oResult["returnValue"], Integer)
    

    So your problems are not related to your ability to declare arrays but rather the tedious interface to WMI. I guess you might need a few more calls for your console output to be entirely valid but I hope this helps you out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.