views:

302

answers:

1

I'm using the WMI Win32_NetworkAdapterConfiguration Class EnableDHCP Method to enable the DHCP service on a network adapter. I'm using XP Embedded with SP2 but it also happens on my desktop (XP SP3).

Everything works great except when the network cable is unplugged.

If the cable is disconnected, EnableDHCP returns 94 (Path, file, or object not found) and when I look in the network control panel properties, it is set to manual configuration with address 0.0.0.0 and mask 255.0.0.0.

Curiously, when in this state, EnableStatic fails with code 94 or 81 (Unable to configure DHCP service) the first time but then works the second time.

Enabling DHCP works fine using netsh or the windows GUI even with the cable unplugged.

Anybody know how to work around this issue?

+2  A: 

It seems at least one other person is interested so here's what I found:

As far as I can tell it's a bug in WMI. To get around it, what seems to work is to directly set the appropriate registry values for the adapter. These are stored in the registry under

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\<guid>

The guid is contained in the IP_ADAPTER_INFO structure filled in by GetAdaptersInfo.

Set the EnableDHCP DWORD value to 1.

I also found it useful to clear the gateways using WMI SetGateways otherwise the old gateway(s) hang around.

I also found that when EnableStatic says it failed, it actually works.

This stuff is only relevant when the network is disconnected.

markh44