C# - Getting the  FriendlyName from USB Serial Port?

Posted on 2012-08-29
Last Modified: 2012-09-04
Hi Everyone.
How to get the InstanceName from a USB Serial Port?
if we use the code below will display all Serial Port!
CommPort com=CommPort.Instance;
            int foundRSP=0;

            string[] portList=com.GetAvailablePorts();
            #region This code takes all the serial ports
            for(int i=0;i<portList.Length;++i)
                string name=portList[i];


Open in new window

However I need to show only the USB Serial Port.
I tried this way and not succeeded.
            ManagementObjectSearcher searcher=new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSSerial_PortName");
            string[] USBPorts=System.IO.Ports.SerialPort.GetPortNames();
            #region In this code I need only the USB Serial Port

            //FriendlyName, PID & VID.

            foreach(ManagementObject queryObj in searcher.Get)
                lbl_InstanceName.Text="InstanceName: {0}"+queryObj["InstanceName"];
                lbl_PortName.Text="PortName: {0}"+queryObj["PortName"];

                //If the serial port's instance name contains USB Serial Port
                //it must be a USB to serial device
                if(queryObj["InstanceName"].ToString().Contains("USB Serial Port"))

Open in new window

Thanks in advance,
Question by:ocaccy
    LVL 96

    Accepted Solution

    Did you try Win32_SerialPort.Description?

    Author Comment

    Not yet!
    This function will need to work on XP, VISTA and 7.
    I Would like to work in direction of your tip.
    Have you any suggestion to link?
    LVL 19

    Assisted Solution

    by:Manoj Patil

    Author Closing Comment

    Thank you, still not as I need, but this much better than before his comments.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now