Discussion Locked

Disable / Enable Network connection

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,

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!

Alexander

6 replies

by jaqui

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.

by alebar

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

by bfilmfan

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
objNetCard.ReleaseDHCPLease()
Next

An extensive list of WMI scripts are available here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks_for_scripts_and_applications.asp?frame=true

by alebar

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?

by gradindotcom

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.

This discussion is closed to new replies.