Since this is my first time to create a application which can change ip address i have here sample codes the problem is my address not changing still its old ip address. in my code i just declare string only to test if its working. my OS is windows 8.
private void button1_Click_1(object sender, EventArgs e)
{
//example of ip 10.11.3.120
//click the button it change to ip 10.11.3.120
setIP();
}
private void setIP()
{
ManagementClassobjMC = newManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollectionobjMOC = objMC.GetInstances();
foreach (ManagementObjectobjMOinobjMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObjectsetIP;
ManagementBaseObjectnewIP =
objMO.GetMethodParameters("EnableStatic");
stringip_address = "10.11.3.120";
stringsubnet_mask = "255.255.255.0";
newIP["IPAddress"] = newstring[]{ ip_address};
newIP["SubnetMask"] = newstring[]{ subnet_mask};
setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
}
catch (Exceptionex)
{
MessageBox.Show(ex.ToString());
}
}
}
}