Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
In the form I have comboBox1, when I click on comboBox1 then selects a network adapter and it works.

I would like to:
when I select a network adapter, as a result in the "Label1.Text" will be:
Wi-Fi or Ethernet.
Code that has so far is below (and it works).
Please Help. Thank you.

What I have tried:

private void Form1_Load(object sender, EventArgs e)
       {
           ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter Where AdapterType='Ethernet 802.3'");
           foreach (ManagementObject mo in mos.Get())
           {
               comboBox1.Items.Add(mo["Name"].ToString());
           }

       }
Posted
Updated 1-Mar-17 7:45am
v2

Try the NetworkInterfaceType property:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
    {
    if (ni.OperationalStatus == OperationalStatus.Up)
        {
        Console.WriteLine(ni.NetworkInterfaceType.ToString());
        }
    }
 
Share this answer
 
Thanks, but this code detects the type of network adapter that is active, and I want to detect the type of network adapter what I select it.
example:
If you have two adapters (Wi-Fi and Ethernet), and Wi-Fi is active and the Ethernet is not active, and if I select Ethernet to get the result = Wireless80211.
or 
if the active Ethernet and Wi-Fi is not active, and I select Wi-Fi as a result get = Ethernet.
 
Share this answer
 
Comments
Graeme_Grant 1-Mar-17 21:01pm    
Please use the Have a question or comment? or reply button when replying and NOT Add your solution here. You have been asking question long enough on here to know better.

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