1

I am developing a C# windows application using .NET Framework v3.5.

Every USB device should have a unique instance id that distinguishes a it from other devices of the same type on a computer.

In case that the device InstanceID is not unique, the PnP manager modifies the InstanceID, and combines it with the corresponding DeviceTypeID, to create a device instance ID that is unique in the system.

I need to find if the USB Device Instance Id is unique system-wide.

I can use IRP_MN_QUERY_CAPABILITIES to retrieve the device capabilities, and then check the UniqueID member of the DEVICE_CAPABILITIES to indicate if a instance ID is unique across the system.

My questions are:

  1. How can I use IRP_MN_QUERY_CAPABILITIES in c#
  2. Is there a C++ sample code on how to use this query?
  3. Is there any other way to know if the instance id is not unique?

2 Answers 2

0

Device Instance ID is not unique because there is no standard world wide. And I have worked on USB flash drives. However the device instance could show the company's name, and that distinguishes a device from one company from another. The only unique data that I know of is the long Device Serial number, retrieved from a random number generator. If you're using Windows, you can learn about WMI and its ability to access USB devices.

Sign up to request clarification or add additional context in comments.

Comments

0

I found a solution, I used SetupDiGetDeviceRegistryProperty and asked for the DEVICE_CAPABILITIES structure

 private static bool IsDeviceIdUnique(IntPtr usbDev, NativeMethods.SP_DEVINFO_DATA devInfoData,string deviceId)
    {
        uint bufferSize;
        uint propertyRegDataType;
        var buffer = new byte[WinConstants.MAX_PATH];
        NativeMethods.SetupDiGetDeviceRegistryProperty(usbDev, ref devInfoData, WinConstants.SPDRP_CAPABILITIES, out propertyRegDataType, buffer, WinConstants.MAX_PATH, out bufferSize);
        var capabilities = BitConverter.ToUInt32(buffer, 0);
        return (capabilities & WinConstants.CM_DEVCAP_UNIQUEID) == WinConstants.CM_DEVCAP_UNIQUEID;
    }

1 Comment

This is not enough. The CM_DEVCAP_UNIQUEID usually only means that the USB device is providing a serial number. You need to find a statement from the device manufacturer that the Serial Numbers programmed into any USB device with a given VID and PID are unique.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.