Updating DNS Config - Programming Question.

Discussion in 'OT Technology' started by Slid., Jul 29, 2004.

  1. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    I'm writing a program that makes changes to the computers DNS settings in the registry:

    At HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces

    {key with lots of numbers}

    NameServer

    The value that I am changing is NameServer. You'll see that if you set your own DNS to 1.1.1.1 then search for it NameServer contains that value. The prolem is that if I change this value (IN THE REGISTRY) I need to reboot for settings to apply - when doing it manually by openning TCP/IP and clicking OK the changes happen automatically (Windows XP).

    Does anyone know a way to make my registry changes take effect immediatly? The reboot isn't a problem but I'd rather not have to do it.

    Thanks!
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    hmmm, i wonder if you could disable and enable the interface programatically?? Try change the registry setting programatically and then right clicking your network interface in Network Connections, disable, then enable. If that does it, i bet you could find some code to just do that. I know it can be done because 3rd party VPN software has control over all that crap.. it's just a matter of how.
     
  3. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    Enable and disable might do it - I'll check into that - thanks.
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    any luck?
     
  5. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Is there a reason you wouldn't do this via a DHCP server? I mean that's kind of what it's there for - updating items like this dynamically.
     
  6. maczter

    maczter Life is trying things to see if they work.

    Joined:
    Sep 30, 2003
    Messages:
    3,622
    Likes Received:
    0
    Location:
    Austin, TX
    IBHe'smakingavirus/spyware
     
  7. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    :eek3:

    SLED:

    I got it to work today. It took quite some time to find the code to actually disable and enable LAN but after getting it all together it works flawlessly.

    Thanks for the idea!

    This is a program going on retail computers that will limit web access to certain sites. We needed a way to keep the 'white' and 'black' lists updated so my program checks with our server every 15 mins for updates and downloads as neccessary. We have several store locations with some several states away so its not as simple as me going out to each one when we need to update.
     
  8. maczter

    maczter Life is trying things to see if they work.

    Joined:
    Sep 30, 2003
    Messages:
    3,622
    Likes Received:
    0
    Location:
    Austin, TX
    I stand corrected.

    Excellent good use of potentially evil code. :)
     
  9. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    So this is a one time change only to all of the computers? Or ongoing?
     
  10. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    After installing the program it will update itself from our server - so it is an ongoing.

    The reason I need to disable then enable the network is so it refreshes my new DNS information. I *assume* we will never change the DNS but this is more so if someone in the store thinks they are tricky and sets the DNS to a known GOOD server so they can surf the web. If they set it to a good server then it would only be reset on reboot - being able to now restart the network if they change it I can change it right back.

    Some computers use DHCP, some use Static IP addresses so when my program first installs it saves their original DNS address and when/if uninstalled everything is returned to its original setting.

    This project is more or less for getting one peice of software on all computers that allows me to install things across the board. By theory I won't have to do AS much travel for software issues.
     
  11. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    VERY :cool: Sounds like a fun app to work on.

    mind sharing the enabling/disabling code? :x:
     
  12. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Wait, wouldn't the user need to have admin right on the computer to be able to edit the network adapter settings? I guess you could compile it as a windows service, that might work better, since you can specify the login that it uses. Well, now that i think about it, you could impersonate the admin account inside your app. That would work too, as log as the password doesn't change often.
     

Share This Page