如何用程序来设置计算机的网络信息,如Ip,子网掩码,DNS,网关等等... 如何用程序来设置计算机的网络信息,如Ip,子网掩码,DNS,网关等等... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 动态改变/添加网络设置中的TCP/IP的DNS地址 例如,把 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; 在NT上, 先获得网络设备驱动程序的名称: sNetCardRegKey := '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1'; 1 或者其他能在这个地方枚举到的子键regRootKey.RootKey := HKEY_LOCAL_MACHINE;regRootKey.OpenKeyReadOnly(SNetCardRegKey);sNetCardDriverName := regRootKey.ReadString('ServiceName');然后: sServiceRegKey := '\SYSTEM\CurrentControlSet\Services\'; sTCPIPRegKey := sServiceRegKey + sNetCardDriverName + '\Parameters\Tcpip';在'IPAddress'中获得这个设备的所有IP地址 regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);在'SubNetMask'中获得IP地址对应的子网掩码 regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);在Win95/98中:获得设备名称的办法: sNetCardRegKey := '\Enum\Network\MSTCP\0001\'; 0001 或者其他能在这个地方枚举到的子键 sServiceRegKey := '\SYSTEM\CurrentControlSet\Services\Class\'; regRootKey.RootKey := HKEY_LOCAL_MACHINE; regRootKey.OpenKeyReadOnly(SNetCardRegKey); sNetCardDriverName := regRootKey.ReadString('Driver');然后: sTCPIPRegKey := sServiceRegKey + sNetCardDriverName; regRootKey.OpenKeyReadOnly(sTCPIPRegKey);最后获得IP地址和子网掩码:sIPAddress := regRootKey.ReadString('IPAddress');sNetMask := regRootKey.ReadString('IPMask'); DWGZ() : 在'IPAddress'中获得这个设备的所有IP地址 regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);在'SubNetMask'中获得IP地址对应的子网掩码 regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);其中:cIPAddressArray和cNetMaskArray应该怎么定义啊? memtableeh这个控件求指点。 #0如何转PChar 出现这个错误是什么意思 怎么解决 各位;侠哥,侠姐帮帮忙 文件关联 POS 机的通讯 问一个关于select查询的问题! 怎样使得一个String变量转换成array[0..255] of char(即数组变量) 的变量? 长整数处理问题 怎样用FileStream往文件结尾填充指定字节的空白? 怎么用bde读如不是dbf为后缀的dbf文件? 如何将桥牌分给四个人呀!急!!!!
例如,把 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;
sNetCardRegKey := '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1'; 1 或者其他能在这个地方枚举到的子键
regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString('ServiceName');然后:
sServiceRegKey := '\SYSTEM\CurrentControlSet\Services\';
sTCPIPRegKey := sServiceRegKey + sNetCardDriverName + '\Parameters\Tcpip';
在'IPAddress'中获得这个设备的所有IP地址
regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);
在'SubNetMask'中获得IP地址对应的子网掩码
regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);在Win95/98中:
获得设备名称的办法:
sNetCardRegKey := '\Enum\Network\MSTCP\0001\'; 0001 或者其他能在这个地方枚举到的子键
sServiceRegKey := '\SYSTEM\CurrentControlSet\Services\Class\'; regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString('Driver');然后:
sTCPIPRegKey := sServiceRegKey + sNetCardDriverName;
regRootKey.OpenKeyReadOnly(sTCPIPRegKey);最后获得IP地址和子网掩码:
sIPAddress := regRootKey.ReadString('IPAddress');
sNetMask := regRootKey.ReadString('IPMask');
在'IPAddress'中获得这个设备的所有IP地址
regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);
在'SubNetMask'中获得IP地址对应的子网掩码
regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);其中:cIPAddressArray和cNetMaskArray应该怎么定义啊?