Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I want to get total no of all the available USB ports in my PC using programming in C#?
Posted
Updated 6-Jan-21 20:12pm
Comments
Mehdi Gholam 24-Mar-14 3:00am    
Why?
R0bb 21-Nov-22 5:19am    
Why not?
[no name] 24-Mar-14 3:15am    
Agree with above and what do you mean by "available". Has no meaning.
Bernhard Hiller 24-Mar-14 3:22am    
I'd try Windows Management Instrumentation (WMI), but I haven't taken such a close look at it to be sure about USB ports...

Try this

SQL
Well, after studying several forums, I discovered that the com port associated to the USB/RS485 adapter is listed if I run the query SELECT * FROM Win32_PnPEntity .

But I really don't understand why the serial port of the arduino is shown by a query and the other port with the other query.... I mean, those are both uSB<->serial adapters!



OR

CSS
Maybe you can use a C# to USB device library as described here:
Are there any good C# to usb device libraries?

From the above answer: For getting a list of devices connected:
http://code.google.com/p/usb-devices-list/
 
Share this answer
 
SELECT * FROM Win32_portconnector where ExternalReferenceDesignator like '%USB%'

this will give list of all USB ports

ManagementObjectSearcher search= new ManagementObjectSearcher("\\root\\wmi", "SELECT * FROM Win32_portconnector where ExternalReferenceDesignator like '%USB%'");

foreach (ManagementObject managementObject in searcher.Get())
            {

                string s = managementObject["ExternalReferenceDesignator"].ToString();
                string s1 = managementObject["InternalReferenceDesignator"].ToString();
}
 
Share this answer
 
v4

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