Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public void setIP () {
  2. ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
  3. ManagementObjectCollection objMOC = objMC.GetInstances();
  4.  
  5. foreach (ManagementObject objMO in objMOC) {
  6. if (!(bool) objMO["IPEnabled"]) {
  7. continue;
  8. } else if ((String) objMO["ServiceName"] != "msloop") {
  9. continue;
  10. }
  11.  
  12. try {
  13. ManagementBaseObject objNewIP = objMO.GetMethodParameters("EnableStatic");
  14. ManagementBaseObject objNewGate = objMO.GetMethodParameters("SetGateways");
  15.  
  16. objNewIP["IPAddress"] = new string[] { "110.110.110.1" };
  17. objNewIP["SubnetMask"] = new string[] { "255.255.255.252" };
  18.  
  19. objNewGate["GatewayCostMetric"] = new string[] { "1" };
  20.  
  21. objMO.InvokeMethod("EnableStatic", objNewIP, null);
  22. Console.WriteLine("EnableStatic End");
  23. objMO.InvokeMethod("SetGateways", objNewGate, null);
  24. Console.WriteLine("SetGateways End");
  25.  
  26. Console.WriteLine("Change OK");
  27. Console.WriteLine("==================================================================");
  28. } catch (Exception ex) {
  29. MessageBox.Show("Unable to Set IP : " + ex.Message);
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement