Mega Code Archive

 
Categories / Delphi / Examples
 

Changing the tcp-ip dns address

A Domain Name Server convert mnemonic internet addresses to their natural numeric IP addresses e.g. preview.org = 209.204.209.81 If you have a need to dynamically change your DNS servers from your program, you can do so by calling the the following uses Registry; procedure SaveStringToRegistry_LOCAL_MACHINE (sKey, sItem, sVal: string); var Reg : TRegIniFile; begin Reg := TRegIniFile.create (''); Reg.RootKey := HKEY_LOCAL_MACHINE; Reg.WriteString (sKey, sItem, sVal + #0); Reg.Free end; procedure SetTCPIPDNSAddresses (sIPs: string); begin if RunningWinNT then begin // // if using Windows NT // SaveStringToRegistry_LOCAL_MACHINE ( 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'NameServer', sIPs) end else begin // // if using Windows 95 // SaveStringToRegistry_LOCAL_MACHINE ( 'SYSTEM\CurrentControlSet\Services\VxD\MSTCP', 'NameServer', sIPs) end end;