2011-04-18 76 views

回答

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; 
} 
+0

知道如何添加WINS條目也會很棒嗎? – Vijay 2011-04-25 12:30:15

+0

@Vijay:看到這裏的一些提示 - http://us.generation-nt.com/answer/programmatically-setting-dns-wins-address-help-28260902.html – 2011-04-25 17:58:45