0

I have to programatically add DNS server address in network adapter settings on windows. Programming language is C++.

Vijay
  • 2,021
  • 4
  • 24
  • 33

2 Answers2

1

You can take a look to the IP Helper API

You can find how to use it There

M'vy
  • 5,696
  • 2
  • 30
  • 43
0

Setting DNS using iphelp and register at CodeProject.

bool RegSetDNS(LPCTSTR lpszAdapterName, LPCTSTR pDNS)
{
    HKEY hKey;
    string strKeyName = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
    strKeyName += lpszAdapterName;
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                strKeyName.c_str(),
                0,
                KEY_WRITE,
                &hKey) != ERROR_SUCCESS)
        return false;

    char mszDNS[100];

    strncpy(mszDNS, pDNS, 98);

    int nDNS;

    nDNS = strlen(mszDNS);

    *(mszDNS + nDNS + 1) = 0x00;    // REG_MULTI_SZ need add one more 0
    nDNS += 2;

    RegSetValueEx(hKey, "NameServer", 0, REG_SZ, (unsigned char*)mszDNS, nDNS);

    RegCloseKey(hKey);

    return true;
}
  • it would be great to know how to add WINS entry too? – Vijay Apr 25 '11 at 12:30
  • @Vijay: See here for some hints - http://us.generation-nt.com/answer/programmatically-setting-dns-wins-address-help-28260902.html –  Apr 25 '11 at 17:58