Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 port
Aam trying to populate list of available ports in my system.
Following is my code which works in windows xp, but does not work in windows 7
 
public void loadPorts()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_PnPEntity");
 
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Caption"].ToString().Contains("(COM"))
                    {
                        cmbPort.Items.Add(queryObj["Caption"]);
                    }
 
                }
            }
            catch (ManagementException e)
            {
            }
        }
Posted 28-May-13 0:48am
Comments
lukeer at 28-May-13 5:58am
   
What is the desired behaviour?
What does actually happen?
Is there an error message?
What line does yields the error?
Himu from Orissa at 28-May-13 5:59am
   
aam not getting the list of com ports in the combobox

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
string[] ports = SerialPort.GetPortNames();
foreach (string p in ports)
    {
    Console.WriteLine(p);
    }
  Permalink  
Comments
Himu from Orissa at 28-May-13 6:43am
   
actually i need the name also e.g.(Communication Port), but in this method it only gives com1,com2 etc

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 28 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100