I have an application written in C# that needs to be able to configure the network adapters in Windows. I have this basically working through WMI, but there are a couple of things I don’t like about that solution: sometimes the settings don’t seem to stick, and when the network cable is not plugged in, errors are returned from the WMI methods, so I can’t tell if they really succeeded or not.
I need to be able to configure all of the settings available through the network connections – Properties – TCP/IP screens.
What’s the best way to do this?
You could use
Processto fire off netsh commands to set all the properties in the network dialogs.eg: To set a static ipaddress on an adapter
To set it to dhcp you’d use
To do it from C# would be
Setting to static can take a good couple of seconds to complete so if you need to, make sure you wait for the process to exit.