如何编程设置本机IP地址?Wait on line..........

DelphiStudy 2002-11-24 02:34:22
求教如何编程设置本机IP地址?

多谢了。
...全文
274 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhzxf 2002-12-25
  • 打赏
  • 举报
回复
程序中执行DOS命令:
winexec(pchar('netsh interface ip set address name="本地连接" source= static addr= '+要设置的IP+' mask='+子码),SW_HIDE);
其中"本地连接"为"控制面板"->"网上邻居"中显示的本地局域网连接名称,可以更改名字
dragonimp 2002-12-17
  • 打赏
  • 举报
回复
这样好像不会马上生效吧,要禁用再启用才行吧?!
可以用netsh 命令行可以设置,不知道怎么用程序写出同样效果的
ppbaobei123 2002-12-01
  • 打赏
  • 举报
回复
知道IP在什么位置,就可以更改了,看看下面这个


在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');
Win95不支持一个设备对应多个地址

DelphiStudy 2002-11-24
  • 打赏
  • 举报
回复
能具体一点吗?
在哪个键值里改?
cbdiy 2002-11-24
  • 打赏
  • 举报
回复
改注册表

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧