Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
foreach (ManagementObject result in search.Get())
{
    NetworkAdapter adapter = new NetworkAdapter(result);//error in this line whats the problem
                
    if (adapter.AdapterType.Equals("Ethernet 802.3"))
    {
        adapter.Disable();
    }
}


i have also added reference System.net;

[edit]rjm: added code formatting[/edit]
Posted
Updated 14-Feb-10 23:03pm
v3

rahul_12789 wrote:
//error in this line whats the problem


What's the error? Please understand that people reading your question cannot guess what goes wrong in your code.
 
Share this answer
 
Comments
Bassem Zeft 30-Dec-13 12:56pm    
I think this is the error he is refering to because I have it too:

Error 1 The type or namespace name 'NetworkAdapter' could not be found (are you missing a using directive or an assembly reference?) c:\users\electron\documents\visual studio 2013\Projects\Network Card\Network Card\Form1.cs 50
Richard MacCutchan 31-Dec-13 4:51am    
Then you need to add the library to your references and include a using statement for the namespace.
Bassem Zeft 15-May-14 11:52am    
Thanks Richard for your answer, I just saw it now cause I had to work on other projects.
result.InvokeMethod("Disable", null);
try this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900