Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:23:59+00:00 2026-06-04T10:23:59+00:00

I have the following class that enumerates all COM ports on the local PC,

  • 0

I have the following class that enumerates all COM ports on the local PC, finding and storing only those with a friendly name that starts with the given prefix.

Now, assuming I know such COM ports are part of a composite device and that the composite device also has a network adapter, how can I find the network adapter associated with the given device? I’m sure there must be a relatively simple way of doing this (both devices will have the same parent node I think), but I’m not sure what the non-interop method would be… Can anyone assist?

Here is the class:

/// <summary>
/// A class to enumerate all COM ports through USB.
/// </summary>
public class SerialPortUSB
{

    /// <summary>
    /// Structure to store a port name and details.
    /// </summary>
    public struct PortName
    {
        public string Port;
        public string Fullname;
        public bool HadPrefix;
    };

    /// <summary>
    /// Function to return all ports with the given prefix.
    /// </summary>
    /// <param name="prefix"></param>
    /// <returns></returns>
    static public List<PortName> PortsWithPrefix(string prefix)
    {
        List<PortName> ports = new List<PortName>();

        try
        {
            // Select all COM ports.

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(   "root\\CIMV2",
                                                                                "SELECT * FROM Win32_SerialPort");




            // Now iterate results looking for those that start with the prefix.

            foreach (ManagementObject item in searcher.Get())
            {
                string friendlyName = (string)item["Caption"];

                if (!friendlyName.StartsWith(prefix))
                {
                    continue;
                }




                // Construct an item for this.

                PortName name = new PortName();

                int start = friendlyName.LastIndexOf('(') + 1, end = friendlyName.LastIndexOf(')');

                name.HadPrefix = true;

                name.Port = friendlyName.Substring(start, end - start);
                name.Fullname = friendlyName;

                ports.Add(name);
            }
        }
        catch (ManagementException e)
        {
            // Failed to find any...
        }




        // Return the list of ports.

        return ports;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:24:01+00:00Added an answer on June 4, 2026 at 10:24 am

    Thought I’d reply to my own, rather than deleting the question just in case someone else finds the answer useful.

    It turns out the PNPDeviceID, a property present in both Win32_SerialPorts and Win32_NetworkAdapters contains an ID unique to the device, so it’s possible to identify them both. The solution is first to enumerate the serial ports, then extract the unique part of the PNPDeviceID and then to find all network adapters that are LIKE ‘%value%’, where value is part of the PNPDeviceID.

    Turns out the number is the same for both, i.e.:

    Serial Port PNPDeviceID = USB\VID_17DC&PID_0500&MI_02\8&18F2972&0&0002″

    and

    Network Adapter PNPDeviceID = USB\VID_17DC&PID_0500&MI_00\8&18F2972&0&0000″

    , where the common ID is 18F2972.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class that extends Backbone.View, I want all my backbone views
I have a class that looks like the following: public class MyClass { private
We have a class a class that looks something like the following: public class
I have the following ugly if statement that is part of a class that
Assume that we have the following code: class Program { static volatile bool flag1;
I have a class that has the following property that is generated by the
I have following code snippet that i use to compile class at the run
So I have a class that has the following member variables. I have get
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
Lets say that I have the following code: public class Shelter<A extends Animal, B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.