Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically detect if a PC has USB3 capability?

Tags:

c++

windows

usb

This seems like it should be a simple question, but I'm not sure how best to solve it. I've seen a few posts on how to detect if a connected device is USB 2 or 3, but I need to know if USB 3 ports are available, even if no devices are connected.

One solution would be to traverse the 'SYSTEM\CurrentControlSet\Services' key in the registry and compare against a pre-set list of known USB3 services. I was hoping there was something more accurate like an IOCTL call.

I can implement C++ (preferred) or C#.

Thanks in advance for any help.

like image 840
Randall Deetz Avatar asked Nov 27 '25 00:11

Randall Deetz


1 Answers

Here's how I implemented this. Not really the solution I'm looking for. This basically will tell me if USB 3.0 drivers are present on the system. It does not detect if the hardware on the system includes USB 3.0 ports. Would prefer something lower level in C++.

I would greatly appreciate it if someone could show me how to detect the hardware for this (rather than just slag and not contribute). Thanks!

    private bool IsUsb3()
    {
        string val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBXHCI", "ImagePath", 0);
        if (val != null) return true;   // Microsoft
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\USBHUB3", "ImagePath", 0);
        if (val != null) return true;   // Microsoft
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\usb3Hub", "ImagePath", 0);
        if (val != null) return true;   // Microsoft
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\UCX01000", "ImagePath", 0);
        if (val != null) return true;   // Microsoft
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\nusb3hub", "ImagePath", 0);
        if (val != null) return true;   // Renesas
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\nusb3xhc", "ImagePath", 0);
        if (val != null) return true;   // Renesas
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\iusb3xhc", "ImagePath", 0);
        if (val != null) return true;   // Intel
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\iusb3hub", "ImagePath", 0);
        if (val != null) return true;   // Intel
        val = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\iusb3hcs", "ImagePath", 0);
        if (val != null) return true;

        return false;
    }
like image 102
Randall Deetz Avatar answered Nov 28 '25 15:11

Randall Deetz