Connect and Obtain IP address from DHCP

I am writing an application, which get a list of all network interfaces, with their IP address, MAC address and other info.
The interfaces which are connected with internet have obviously IP addresses. For example, My WLAN interface has IP address. For other interfaces, for example if I plug in a 3G card, it gets IP address when I click the CONNECT button on the software came with this card.
I dont want to use that Software to connect my 3G card and get IP address. Rather I want to enable that interface and get IP address from DHCP server programmatically in C++.
In simplest words I want my network card / adapter should be connected and be assigned IP address using C++.
Note: I am using Windows Vista.
Waiting for reply.
Who is Participating?
VolkerBeckConnect With a Mentor Commented:
How about calling the command line tools "netsh" and "ipconfig" shipped with Windows? You can do this from your C++ program.
Here is an example how to change the IP address assignment to DHCP (replace "MyConnection" by the name of your network - see Windows Control Panel):

netsh interface ip set address name="MyConnection" source=dhcp

To reassign the IP address via DHCP after this call:

ipconfig /renew "MyConnection"

Also the command line tool DevCon ( might help you to enable/disable network adapters in the Windows device manager.

Attention: You need real admin rights to do this. On Vista with UAC enabled you need to launch the command line tools with elevation (e.g via ShellExecuteEx or your application already has an according manifest and already runs with real admin rights, see
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.