2

When you configure a network adapter with a certain IP address that was already used before on a currently removed network adapter, you will fail.

If you do this trough the Windows TCP/IP settings GUI, you will be alerted and offered the option to remove the old adapter IP configuration.

How can you achieve the same result trough WinAPI ?

If I use the IP Helper functions (GetAdaptersAddresses, GetAdaptersInfo), they only return the connected adapters.

If I use the Win32_NetworkAdapterConfiguration WMI class by executing the query:

"Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = False"

I get only the disconnected devices, which is perfect, but the "IPAddress" property is empty.

So how can one configure a network adapter with an IP address that was used before by another network adapter which is now not present anymore, through WinAPI ?

Chris
  • 1,213
  • 1
  • 21
  • 38
  • Did you get an answer? I have the same problem... – liorda Nov 21 '13 at 18:45
  • 1
    @liorda What I did was to hack in the registries. I loop through HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces and see if any of the interfaces have the field IPAddress containg the IP address I want to use. If I find one, then I check to see if it is in my list of connected interfaces. If it is in the list I issue a "IP duplicate" error. If it is not, I set the IPAddress field of that interface to it's default value "0.0.0.0" and set EnableDHCP to 1, so that if it ever comes back online it gets an IP configuration through DHCP. Then I can use that IP address. – Chris Dec 08 '13 at 14:34
  • 1
    @Chris, that's a legitimate answer (even if not the one you really wanted). Post it as such and accept your own solution. – Brian White Apr 25 '15 at 12:49

0 Answers0