Sign in to follow this  
3DModelerMan

Change network adapter settings Win32 API?

Recommended Posts

I have a system that I commonly need to change my static IP address settings to work with. The settings are VERY specific and it becomes a huge pain to switch between my normal IP address and my IP address for working with it. Alot of times I'll have to have my phone out to read documentation because the adapter settings won't work for the network I'm on. Is there any way to change network adapter settings from C/C++ and/or the Win32 API? I'd like to write a tool that can quickly automate the switch to different network settings, and then be able to switch back to the previous settings.

Share this post


Link to post
Share on other sites

Not sure if it is possible through the Win32 API or not (it should be possible), but you could always use the system function and the standard windows commandline tools for configuring the network.

 

http://www.petri.co.il/configure_tcp_ip_from_cmd.htm

 

if you just need to switch between one or two configurations its easier to just write a batch script for it and create desktop shortcuts to it.

Edited by SimonForsman

Share this post


Link to post
Share on other sites

I guess that would work I'll probably just go with the system command. What about a way to at least query the current settings so that I can store the settings I had before running the tool?

Share this post


Link to post
Share on other sites

I guess that would work I'll probably just go with the system command. What about a way to at least query the current settings so that I can store the settings I had before running the tool?

 

netsh -c interface dump > c:\location1.txt

 

that dumps the current settings for "interface" to location1.txt

 

netsh -f c:\location1.txt restores them.

 

you can use the windows functions to launch applications if you wish to push the output to a memory buffer rather than a file. (look for the shellexecute functions on msdn)

Share this post


Link to post
Share on other sites

You can write a batch file to do this.

 

However, there is a Win32 API exposed that will ALSO let you do this. You could also use COM/WMI as well.

 

My personal preference? A batch file or something similar.

Share this post


Link to post
Share on other sites

I had to implement configuration of network interfaces for a remotely managed system. I found shelling to netsh to be the most complete and reliable way to do this. The win32 API is incomplete, hacking the registry is a gambit, and WMI has quirks ( for example, if an interface did not have a cable plugged in WMI could not change its settings ).

 

--Z

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this