keyongtech


  keyongtech > dotnet.languages.* > dotnet.languages.csharp > 10/2006

 #1  
09-25-06, 01:53 PM
rongchaua
Hi all,
i would like now to disable and enable network adapter programmatically with
c#. I have searched but found nothing useful. There's no topic about this
problem. Has someone done with this problem?
All help will be appreciated.
rongchaua.
 #2  
09-25-06, 02:33 PM
Ignacio Machin \( .NET/ C# MVP \)
Hi,

There is nothing for this in the framework, you would have to use WMI


--
 #3  
09-25-06, 02:51 PM
Willy Denoyette [MVP]
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:2264
| Hi,
|
| There is nothing for this in the framework, you would have to use WMI


Which is exactly what's exposed by System.Management or is this not part of
the framework.

Willy.
 #4  
09-25-06, 04:18 PM
Ignacio Machin \( .NET/ C# MVP \)
Hi
"Willy Denoyette [MVP]" <willy.denoyette> wrote in message
news:2464

>
> Which is exactly what's exposed by System.Management or is this not part
> of
> the framework.


:) , good point.



--
 #5  
09-26-06, 12:59 PM
rongchaua
Hi,
WMI can not disable or enable NIC.
http://msdn.microsoft.com/library/de...networking.asp
But I found another.
http://channel9.msdn.com/ShowPost.aspx?PostID=158556
Regards.
rongchaua.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
[..]
 #6  
10-02-06, 10:48 PM
rongchaua
Hi all,
today when i look again at this link
http://msdn.microsoft.com/library/de...networking.asp

I see that we can enable or disable NIC
****
Use the Win32_NetworkAdapter class and the Disable or Enable methods.
****

But when I use this method to disable the network adapter I receive a error
message in debug window
****
ManagementException was unhandled
This methode was not implemented
*****

Hier is my source code
***********
ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
ManagementObjectCollection moc = mc.GetInstances();


foreach(ManagementObject mo in moc)
{
ManagementBaseObject mbo = null;
mbo = mo.GetMethodParameters("Disable"); //the error comes here...
}
*************

What should I do now to use this method? Should I update the new version of
..net framework? I'm using now VS 2005 with .net 2.0
All help will be appreciated.
rca.


"rongchaua" wrote:
[..]
 #7  
10-03-06, 11:12 AM
Willy Denoyette [MVP]
The class provides a disable/enable method but they aren't implemented.
It's up to the device driver to accept/implement the commands and currently
none of the network driver implements these methods, that's why the methods
aren't implemented at the WMI provider either.
One option is to get a copy of Devcon.exe from the MS download site, but
keep in mind that this tool is not distributable and should only be used for
diagnostic purposes.
Note that I fail to see why you need to disable a NIC, maybe there is
another way to achieve what you are after.


Willy.


"rongchaua" <rongchaua> wrote in message
news:d15b
| Hi all,
| today when i look again at this link
|
http://msdn.microsoft.com/library/de...networking.asp
|
| I see that we can enable or disable NIC
| ****
| Use the Win32_NetworkAdapter class and the Disable or Enable methods.
| ****
|
| But when I use this method to disable the network adapter I receive a
error
| message in debug window
| ****
| ManagementException was unhandled
| This methode was not implemented
| *****
|
| Hier is my source code
| ***********
| ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
| ManagementObjectCollection moc = mc.GetInstances();
|
|
| foreach(ManagementObject mo in moc)
| {
| ManagementBaseObject mbo = null;
| mbo = mo.GetMethodParameters("Disable"); //the error comes here...
| }
| *************
|
| What should I do now to use this method? Should I update the new version
of
| .net framework? I'm using now VS 2005 with .net 2.0
| All help will be appreciated.
| rca.
|
|
| "rongchaua" wrote:
|
| > Hi,
| > WMI can not disable or enable NIC.
| >
http://msdn.microsoft.com/library/de...networking.asp
| > But I found another.
| > http://channel9.msdn.com/ShowPost.aspx?PostID=158556
| > Regards.
| > rongchaua.
| >
| > "Ignacio Machin ( .NET/ C# MVP )" wrote:
| >
| > > Hi
| > > "Willy Denoyette [MVP]" <willy.denoyette> wrote in message
| > > news:2464
| > >
| > > >
| > > > Which is exactly what's exposed by System.Management or is this not
part
| > > > of
| > > > the framework.
| > >
| > > :) , good point.
| > >
| > >
| > >
| > > --
| > > --
| > > Ignacio Machin,
| > > ignacio.machin AT dot.state.fl.us
| > > Florida Department Of Transportation
| > >
| > >
| > >
 #8  
10-03-06, 02:41 PM
S. Lorétan
Hi,

You can disable a network adapter with this shell command:

> netsh interface set interface "Network Adapter name" DISABLED


And enable it with

> netsh interface set interface "Network Adapter name" ENABLED


This works only under Windows 2003 Server. The problem with Windows 2000/XP
is because the Netshell tools treats network adapters as dedicated
interfaces, and dedicated interfaces can't be enabled or disabled. There is
a workaround if you want to prevent traffic from being passed by the network
adapter. You can use netsh to set a different (private) IP address, which
virtually disable the network adapter.

> netsh interface ip set address "Network Adapter name" static (ip address)
> (subnet mask) (default gateway) (metric)


And to virtually enable it, you can simply reset its IP with the DHCP

> netsh interface ip set address "Network Adapter name" source=dhcp


I hope this helps. Sorry for my english.
 #9  
10-03-06, 02:47 PM
S. Lorétan
Sorry, I forgot to add this link to my post:

http://support.microsoft.com/kb/262265/
Similar Threads
How do I enable DHCP on my network adapter?

When I check the status of my network adapter, it says that DHCP is not enabled. How do I enable it in Windows Vista Ultimate? I'm trying to enable it for ICS to/with a...

How enable network adapter in script?

On Windows XP Pro SP2 I need to enable or disable a network adapter using netsh.exe but the command: netsh interface set interface name="Wired LAN" admin=ENABLED fails with...

Enable a network adapter in XP using WMI with C++

I'm trying to find a way to enable a network interface with C++. After trying various methods, I ended up looking at WMI. I found a Win32_NetworkAdapter class that had an...

Enable Network Adapter in win98 / Me

Hi, I am trying to enable network adapter through SetupAPIs. I am using SetupDiChangeState Method and have also tried SetupDiCallClassInstaller Method. The code is working...

enable/disable network adapter

I am looking for a way to quickly disable and enable network adapters from the command line. I'm pretty sure Netsh can do it but I haven't been able to find exactly how. ...


All times are GMT. The time now is 07:50 AM. | Privacy Policy