3

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.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Randall Deetz
  • 512
  • 4
  • 25
  • USB ports aren't "countable", as you can expand them using hubs. Also, without OS tag, this is solliciting answers like `lsubs`/`lshw`/`ls /sys/bus/usb/devices/`. Please see [SU] or [SF] – sehe Aug 21 '13 at 20:15
  • "How do I determine if a PC has USB 3 ports?" - you read the manual that comes with the PC. –  Aug 21 '13 at 20:16
  • @sehe I don't think he wants to count ports. An USB 3 port is not the same as 3 USB ports. –  Aug 21 '13 at 20:17
  • @H2CO3 You're right of course. Still, the same hints apply :/ – sehe Aug 21 '13 at 20:18
  • @sehe Yes, still off-topic :( –  Aug 21 '13 at 20:18
  • 1
    Confused by the responses, especially the one about reading the manual. I'm not interested in detecting if my personal PC has USB 3 ports. My software application runs on Win XP through Win 8. It needs to detect if each PC it runs on has USB 3 capability. – Randall Deetz Aug 22 '13 at 01:35

2 Answers2

1

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;
    }
Randall Deetz
  • 512
  • 4
  • 25
0

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.

Randall Deetz
  • 512
  • 4
  • 25
  • Why are you checking for full speed, that's available since USB 1.0. Shouldn't you look for USB SuperSpeed? – Ben Voigt Sep 03 '13 at 06:31
  • Also, that doesn't look "straight from Microsoft". – Ben Voigt Sep 03 '13 at 06:31
  • Sorry, you're right on the speed: Low=1.0, Full=1.1, High=2.0, Super=3.0 – Randall Deetz Sep 03 '13 at 06:44
  • Google lead me to this page. The code is from USBView, which is a Microsoft tool. If you want to download the entire app, it's available at the DevCenter. – Randall Deetz Sep 03 '13 at 06:57
  • I'm pretty sure that the real USBView sample actually is written in C++, but that code is C#. Also the download isn't from Microsoft. There's a very good chance that some Microsoft engineer had a hand in writing it, but it isn't an official sample. – Ben Voigt Sep 03 '13 at 12:48
  • The link is dead - can you provide any more info as your code provided will not work alone – IamSierraCharlie Sep 07 '19 at 07:25