Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to set "automatic dns" using wmi?

how to set "automatic dns" using wmi?

Scheduled Pinned Locked Moved C#
questioncsharpsysadminjsontutorial
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krzysztof Gorgolewski
    wrote on last edited by
    #1

    good evening out there, i'm working on a routine (using c# + wmi) that is able to change my network configuration e.g. dhcp<->static, different ip/gateway/subnet addresses etc (just like the build-in windows tcp/ip network configuration). everything works fine, but i can not find any way of switching between static defined dns servers and automatic leased dns servers (which i receive automatic from my router or equivalent). i mean, what is the counter part for "EnableDNS", like "EnableDHCP" is for "EnableStatic"? i can not find it in the windows api... greetings criss

    D K 2 Replies Last reply
    0
    • K Krzysztof Gorgolewski

      good evening out there, i'm working on a routine (using c# + wmi) that is able to change my network configuration e.g. dhcp<->static, different ip/gateway/subnet addresses etc (just like the build-in windows tcp/ip network configuration). everything works fine, but i can not find any way of switching between static defined dns servers and automatic leased dns servers (which i receive automatic from my router or equivalent). i mean, what is the counter part for "EnableDNS", like "EnableDHCP" is for "EnableStatic"? i can not find it in the windows api... greetings criss

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There isn't one. DNS will get set back to DHCP if you enable DHCP on the IP address. You can't have DHCP DNS without a DHCP enabled IP pickup.

      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      K 1 Reply Last reply
      0
      • D Dave Kreskowiak

        There isn't one. DNS will get set back to DHCP if you enable DHCP on the IP address. You can't have DHCP DNS without a DHCP enabled IP pickup.

        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        K Offline
        K Offline
        Krzysztof Gorgolewski
        wrote on last edited by
        #3

        hi dave, so that means, if i call EnableDHCP all entries in my dns list will be deleted and it becomes "automatic"? hm, but that's not happening somehow. i can not get rid of any static dns settings. any ideas? criss

        1 Reply Last reply
        0
        • K Krzysztof Gorgolewski

          good evening out there, i'm working on a routine (using c# + wmi) that is able to change my network configuration e.g. dhcp<->static, different ip/gateway/subnet addresses etc (just like the build-in windows tcp/ip network configuration). everything works fine, but i can not find any way of switching between static defined dns servers and automatic leased dns servers (which i receive automatic from my router or equivalent). i mean, what is the counter part for "EnableDNS", like "EnableDHCP" is for "EnableStatic"? i can not find it in the windows api... greetings criss

          K Offline
          K Offline
          Krzysztof Gorgolewski
          wrote on last edited by
          #4

          i found the solution... before calling EnableDHCP, i have to clear my DNS list by assigning an empty array to SetDNSServerSearchOrder like

          ...
          newdns["DNSServerSearchOrder"] = new string[] { };
          mo.InvokeMethod("SetDNSServerSearchOrder", newdns, null);
          mo.InvokeMethod("EnableDHCP", null, null);
          ...

          where "mo" is the ManagementObject of my networkcard. regards, criss

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups