Is it possible to set IP address (or anything else) for a network interface which is currently down?
I am using WMI, that means ManagementObjectCollection
and Invoke
methods. But it seems there is no way how to configure IP in c# on a network adapter which is currently down - cable not connected?
There is no error message. For example, i set IP manualy for wifi interface, and by the WMI i want to set it to DHCP.
ManagementObjectSearcher query = new ManagementObjectSearcher("Select * from Win32_NetworkAdapterConfiguration where SettingID=\"" + selectedProfile.AdapterGUID + "\"");
ManagementObjectCollection moc = query.Get();
foreach (ManagementObject mo in moc)
{
ManagementBaseObject newDHCPIP = mo.GetMethodParameters("EnableDHCP");
mo.InvokeMethod("EnableDHCP", newDHCPIP, null);
ManagementBaseObject newDHCPDNS = mo.GetMethodParameters("SetDNSServerSearchOrder");
newDHCPDNS["DNSServerSearchOrder"] = null;
mo.InvokeMethod("SetDNSServerSearchOrder", newDHCPDNS, null);
ManagementBaseObject newDHCPRenew = mo.GetMethodParameters("RenewDHCPLease");
mo.InvokeMethod("RenewDHCPLease", newDHCPRenew, null);
mo.Dispose();
}
I am 100% percent sure i am selecting right network adapter. But when i set it, and look at configuration (by windows network and sharing center, adapter properities) there is still static IP.
It is working only after i connect to the wifi network, then i look at configuration and there is DHCP