如何用程序来设置计算机的网络信息,如Ip,子网掩码,DNS,网关等等...

解决方案 »

  1.   

    动态改变/添加网络设置中的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; 
      

  2.   

    在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');
      

  3.   

    DWGZ() :
     在'IPAddress'中获得这个设备的所有IP地址
     regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);
    在'SubNetMask'中获得IP地址对应的子网掩码
     regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);其中:cIPAddressArray和cNetMaskArray应该怎么定义啊?