HELP: Obtain DNS Server Address Automatically

Discussion in 'Scripting' started by Stevens, Apr 18, 2005.

  1. Stevens

    Stevens Guest

    I have statically assigned the ip addresses of my computers and the ip
    addresses of the dns servers for them. With a wsh script i would migrate to a
    dynamic assignment for the computer ip addresses and for their associated ip
    dns servers addresses.But when the "DNS server addresses" are statically
    assigned the wsh script in the Microsoft Script Center Repository only
    changes the "Obtain an IP Address Automatically" switch but no the "Obtain
    DNS Server Address Automatically". Any ideas?(My O.S. it's Windows XP. SP2)
    Thank you in advance for your help.
    Stevens, Apr 18, 2005
    1. Advertisements

  2. Stevens

    Jim Vierra Guest

    WIN32_NetworkAdapterConfiguration.EnableDHCP = true
    WIN32_NetworkAdapterConfiguration.EnableDNS = true
    Jim Vierra, Apr 19, 2005
    1. Advertisements

  3. Stevens

    stevens Guest

    Firstly thanks Jim for your kindness,
    and abusing of your generosity: you would do me the great favor of sending
    me the code for enable "Obtain the DNS Server Address Automatically". At the
    moment I am using the following code for "Obtain an ip address automatically"

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" &
    "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colNetAdapters = objWMIService.ExecQuery("Select * from
    Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

    For Each objNetAdapter In colNetAdapters
    errEnable = objNetAdapter.EnableDHCP()

    Thanks again.
    stevens, Apr 19, 2005
  4. Stevens

    Jorge Guest

    The code to turn on DNS is almost the same as DHCP:

    On Error Resume Next

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set objNetworkSettings =
    strHostName = "fabrikam1"
    arrDNSSuffixes = Array("", "")
    objNetworkSettings.EnableDNS strHostName, , , arrDNSSuffixes

    You can find pretty much any networking scripts here:

    Best of luck!
    Jorge, Apr 19, 2005
  5. Stevens

    stevens Guest

    For if it could interest the script that works for the question is:

    On Error Resume Next

    Set colNetCards = objWMIService.ExecQuery("Select * From
    Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    For Each objNetCard in colNetCards



    Thanks to all.
    stevens, Apr 20, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.