Web Development

General discussion


Disable / Enable Network connection

By alebar ·

I've been searching for quiet a long time know and still I can't figure out how it is possible to disable and enable a NIC / a network connection. Is there a way doing this with the windows API or with WMI? Thank a lot for any help!


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Jaqui In reply to Disable / Enable Network ...

under the hardware manager you can configure the nix to be active in this profile or not.
under network connections you can stop the nic.

Collapse -

by alebar In reply to

thank you, but I want to disable the nics programmatically, from a c++ programm for example.

Collapse -

by BFilmFan In reply to Disable / Enable Network ...

You cannot enable/disable the NIC, but you can disable the network connection.

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")
For Each objNetCard in colNetCards

An extensive list of WMI scripts are available here:


Collapse -

by BFilmFan In reply to

I also ran across some code here in VB that may work for you:


Collapse -

by alebar In reply to

thanks, thats better but it only works for DHCP enabled interfaces. Isn'T there any way within windows to disable a connection as if you were doing it manually?

Collapse -

by gradinDotCom In reply to Disable / Enable Network ...

Using C++, you may be able to tap into netshell's API for a way to disable your NIC. NetShell can do it, so it's really just a question of whether or not the function is exposed. I'm using C# and facing the same problem. So far, I've discovered no way to do it.

Related Discussions

Related Forums