static extern bool SetupApi_ReadProperty(
     ref SetupApiDeviceEnumerator enumerator,
     DeviceRegistryCode property,
     out RegistryDataType propertyRegDataType,
     byte[] propertyBuffer,
     int propertyBufferSize,
     out uint requiredSize);
        static object ReadDeviceProperty(ref SetupApiDeviceEnumerator enumerator, DeviceRegistryCode property)
        {
            uint             requiredSize;
            RegistryDataType dataType;

            SetupApi_ReadProperty(ref enumerator, property, out dataType, null, 0, out requiredSize);

            var propertyBuffer = new byte[requiredSize];

            if (!SetupApi_ReadProperty(ref enumerator, property, out dataType, propertyBuffer, propertyBuffer.Length, out requiredSize))
            {
                var error = (WinError)Marshal.GetLastWin32Error();
                if (error == WinError.ERROR_INVALID_DATA)
                {
                    return(null);
                }

                throw new Win32Exception(error);
            }

            return(ParseRegistryValue(propertyBuffer, dataType));
        }