请问怎么更改主机名和ip地址

superwing 2004-08-08 06:15:17
如题
...全文
189 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lightnings 2004-08-08
  • 打赏
  • 举报
回复
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if(! (bool) mo["IPEnabled"])
continue;

//Set IPAddress & SubnetMask
inPar = mo.GetMethodParameters("EnableStatic");
inPar["IPAddress"] = new string[] { "202.112.152.171" };
inPar["SubnetMask"] = new string[] { "255.255.255.0" };
outPar = mo.InvokeMethod("EnableStatic", inPar, null);

//set Getway
inPar = mo.GetMethodParameters("SetGateways");
inPar["DefaultIPGateway"] = new string[]{"202.112.152.2"};
outPar = mo.InvokeMethod("SetGateways", inPar, null);
}


需要using system.mangement;
superwing 2004-08-08
  • 打赏
  • 举报
回复
有没有简单点的办法!
Javcs 2004-08-08
  • 打赏
  • 举报
回复
studying

八爪鱼-杭州 2004-08-08
  • 打赏
  • 举报
回复
wmi
http://dev.csdn.net/develop/article/21/21398.shtm

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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