views:

56

answers:

1

Hi,

I have to control a network connection located in the Network folder in Windows XP.

How can I do that with C# ? I have found some method to enable or desable the adapter but it is not my case.

Thanks in advance !

A: 

The Win32_NetworkAdapter Enable and Disable methods should definitely do the trick. Just create the ManagementClass and use that to access the WMI interface. Otherwise you can use a dirty, cheap and yet effective trick and - given the adapter name, you can do

netsh interface set interface "ADAPTER_NAME" DISABLED

Replace DISABLED with ENABLED to re-enable the device, of course. Finally, please mind that you'll need administrative privileges to disable a network adapter (no matters which way you do that) on Vista and 7 so keep that in mind if you wanna use the code on newer windows editions too.

EDIT: Just to clarify, what the suggested solutions will do is equivalent to what happens when you right-click enable/disable from the Network Connections. If that's not what you're after please clarify what you want to do.

emaster70
It's on a PPP connection in the Control Panel / Network Connection.I need to do the same as right click Connect / DisconnectThis will be working ?Thanks in advance