Randall Deetz
Randall Deetz

Reputation: 524

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

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.

Upvotes: 3

Views: 2463

Answers (2)

Randall Deetz
Randall Deetz

Reputation: 524

Here's exactly what I was looking for:

http://read.pudn.com/downloads105/sourcecode/windows/vxd/432626/USBLib/USB.cs__.htm

I then added the following code:

        // Get USB information
        bool supportsUsb3 = false;
        System.Collections.ObjectModel.ReadOnlyCollection<USB.USBController> hostlist = null;
        hostlist = USB.GetHostControllers();
        mControllerCount = hostlist.Count;

        foreach (USB.USBController host in hostlist)
        {
            USB.USBController controller = new USB.USBController();
            controller.ControllerDevicePath = host.ControllerDevicePath;
            USB.USBHub roothub = controller.GetRootHub();

            System.Collections.ObjectModel.ReadOnlyCollection<USB.USBPort> portlist = null;
            portlist = roothub.GetPorts();
            foreach (USB.USBPort port in portlist)
            {
                USB.USBHub hub = port.GetHub();
                if (port.PortSpeed == USBLib.USB.USB_DEVICE_SPEED.UsbSuperSpeed.ToString())
                {
                    supportsUsb3 = true;
                    break;
                }
            }
            if (supportsUsb3)
                break;
        }

I can now determine if the user's PC has USB 3.0 ports. If they only have 2.0 ports, then I can use the previous code to determine if USB 3 drivers are installed.

Upvotes: 0

Randall Deetz
Randall Deetz

Reputation: 524

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;
    }

Upvotes: 1

Related Questions