General discussion

Locked

Disable / Enable Network connection

By alebar ·
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

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| 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
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

Collapse -

by BFilmFan In reply to

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

http://www.vbcity.com/forums/topic.asp?tid=56821

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.

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums