wmi
http://dev.csdn.net/develop/article/21/21398.shtm

解决方案 »

  1.   

    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;