动态改变/添加网络设置中tcp/ip的dns

2019年02月27日 点击:



例如,把 dns server的地址添加为192.0.0.1和192.1.1.0,可调用:

settcpipdnsaddresses(192.0.0.1 192.1.1.0) ;

// 各地址之间用一个空格隔开

1. settcpipdnsaddresses 定义如下:

procedure settcpipdnsaddresses( sips : string );

begin

//

// if using windows nt

//

savestringtoregistry_local_machine(

system\currentcontrolset

\services\tcpip\parameters,

nameserver,

sips );

//

// if using windows 95

//

savestringtoregistry_local_machine(

system\currentcontrolset

\services\vxd\mstcp,

nameserver,

sips );

end;

2. 其中 savestringtoregistry_local_machine 定义:

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;

关闭