Show USB devices connected

May 21, 2018 at 12:14am
Hello everyone, this is my first post in this forum. I've tried searching but found nothing that solves my doubts.

I want to make a program that displays all usb devices connected to my laptop, showing their names, and the COM port they're connected to. Is that possible?

Thanks for your help!
Last edited on May 21, 2018 at 12:17am
May 21, 2018 at 11:03am
A quick google search for "C++ enumerate USB devices" threw up a lot of useful-looking results, so that seems like a good starting point.
Jun 4, 2018 at 11:43pm
I managed to show the COM ports in use, but I'd like to get the name of the connected devices if possible. I used this code:

#using <System.dll>

using namespace System;
using namespace System::IO::Ports;
using namespace System::ComponentModel;

void main()
{
array<String^>^ serialPorts = nullptr;
try
{
// Get a list of serial port names.
serialPorts = SerialPort::GetPortNames();
}
catch (Win32Exception^ ex)
{
Console::WriteLine(ex->Message);
}

Console::WriteLine("The following serial ports were found:");

// Display each port name to the console.
for each(String^ port in serialPorts)
{
Console::WriteLine(port);
}
}
Jun 5, 2018 at 7:00am
Jun 6, 2018 at 2:28pm
That's C# code, I don't know if I can use that in my C++ project
Jun 6, 2018 at 3:55pm
The main thing are the classes from the .NET framework you need to use.
It doesn't matter if you use C++ CLI or C# or VB.NET
Topic archived. No new replies allowed.