I create a profile, select a nic card, select to obtain IP from DHCP but it's not correctly enabled. The result of the action will be red outline. What I want to do is in the blue outline. (I'm talking about the image attached)
Here's the code that tries to enable DHCP:
public static void SetDHCP( string nicName )
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
// Make sure this is a IP enabled device. Not something like memory card or VM Ware
if( (bool)mo["IPEnabled"] )
{
if( mo["Caption"].Equals( nicName ) )
{
ManagementBaseObject newDNS = mo.GetMethodParameters( "SetDNSServerSearchOrder" );
newDNS[ "DNSServerSearchOrder" ] = null;
ManagementBaseObject enableDHCP = mo.InvokeMethod( "EnableDHCP", null, null);
ManagementBaseObject setDNS = mo.InvokeMethod( "SetDNSServerSearchOrder", newDNS, null);
}
}
}
}
Question
ProclaimDragon
I was testing SwitchNetConfig (code available at: http://www.codeproject.com/csharp/OazSwitchNetConfig.asp) but it's not working correctly...
I create a profile, select a nic card, select to obtain IP from DHCP but it's not correctly enabled. The result of the action will be red outline. What I want to do is in the blue outline. (I'm talking about the image attached)
Here's the code that tries to enable DHCP:
Link to comment
https://www.neowin.net/forum/topic/515984-c-enabling-dhcp-on-nic-through-wmi/Share on other sites
11 answers to this question
Recommended Posts