Results 1 to 20 of 35

Thread: How to get vendor id and product id of a USB device on windows system

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default How to get vendor id and product id of a USB device on windows system

    I want to get vendor id and product id of usb device which is plugged inside my windows system.

    i am trying with win32 api functions.

    i can able to know whether device is plugged or unplugged.

    but i cant figure out how to get the vendor id and product id information of a usb device .

    any links or samples to achieve this.

    will this USB_DEVICE_DESCRIPTOR Structure help?

    if so any code sample to use that.

    Any help would be really great..

    Thank you for your time

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to get vendor id and product id of a USB device on windows system


  3. #3
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Thanks for the information friend.

    USB_DEVICE_DESCRIPTOR pDevDesc;

    USB_NODE_CONNECTION_INFORMATION pNodeCon;

    how can i pass the USB_DEVICE_DESCRIPTOR to the USB_NODE_CONNECTION_INFORMATION structure.

    after that i have to use like below for getting device information like vendor id and product id.

    DeviceIoControl(hDevice, // device handle
    IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION , // info of device property
    NULL,
    0,
    pDevDesc, sizeof(PUSB_DEVICE_DESCRIPTOR), // output data buffer
    &dwOutBytes, // out's length
    (LPOVERLAPPED)NULL);


    I have been searching for a long time but no help .

    Kindly help me out.

  4. #4
    Join Date
    May 2010
    Location
    slovakia
    Posts
    47
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: How to get vendor id and product id of a USB device on windows system

    use http://www.libusb.org/

    it's cross-platform and GPL, so less worries in future

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    You can also scan the registry - Windows keeps a list of plugged in USB devices and there VID/PID for driver purposes, but libusb is more portable.

  6. #6
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Thank you all for the reply

    what about trying with win32 api or WMI.

  7. #7
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Dear all,

    Kindly find my code which i wrote to get get vendor id and product id of a USB device on windows system

    // Creates or opens a file or I/O device.
    HANDLE hDevice = CreateFile(TEXT("\\\\.\\G:"), // drive to open
    0, // no access to the drive
    FILE_SHARE_READ | // share mode
    FILE_SHARE_WRITE,
    NULL, // default security attributes
    OPEN_EXISTING, // disposition
    0, // file attributes
    NULL);

    PUSB_DEVICE_DESCRIPTOR pDevDesc;

    DeviceIoControl(hDevice,// device handle
    IOCTL_USB_GET_NODE_CONNECTION_INFORMATION , // info of device property
    NULL,
    0,
    pDevDesc, sizeof(PUSB_DEVICE_DESCRIPTOR), // output data buffer
    &dwOutBytes, // out's length
    (LPOVERLAPPED)NULL);


    qDebug ()<<pDevDesc->iManufacturer;

    qDebug ()<<pDevDesc->idProduct;

    qDebug ()<<pDevDesc->bLength;

    qDebug ()<<pDevDesc->idVendor;

    qDebug ()<<pDevDesc->iSerialNumber;


    when i print this i get the below output

    0
    0
    3
    0
    13

    are the above output are correct?

    if not how can i achive this please guide me i need to get vendor id and product id from the connected usb device?

    Any info would be great help

    Thank you for your time.

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Device Manager and right click the device. Windows will show you the VID and PID of the device so you can compare.

    But the above seems incorrect.

    What are you trying to do exactly? If it's to notice when a device is inserted or removed, there is buildin APIs for this and you will then get a message telling you when a device is inserted or removed - no need to do it yourself. Eg. Look at WM_DEVICECHANGE

  9. #9
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    To be specific , my application has to display the vendor id and product id of a usb device

    Any suggestions on this...

  10. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    I'd start with SetupDiGetClassDevs()

  11. The following user says thank you to squidge for this useful post:

    newb (28th May 2010)

  12. #11
    Join Date
    Apr 2010
    Posts
    48
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get vendor id and product id of a USB device on windows system

    Thank you fatjuicymole for your reply.

    i did tried that do .

    below is the code i tried.

    HANDLE h = SetupDiGetClassDevs(&GUID_CLASS_COMPORT,NULL,NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

    if ( h == INVALID_HANDLE_VALUE )
    {
    qDebug ()<<"invalid";
    }
    else
    {
    qDebug ()<<"valid handle";

    qDebug ()<<h;


    }
    Handle is valid .

    can you please lead me further to proceed.

    Sorry to be annoying because i am very to new Qt and windows programming

    Thank you for your time.

Similar Threads

  1. Get the product/device name using QT library?
    By predatorz in forum Newbie
    Replies: 3
    Last Post: 14th January 2010, 04:53
  2. Vendor and Model Name from USB Devices
    By NoRulez in forum Qt Programming
    Replies: 6
    Last Post: 20th July 2009, 10:01
  3. Replies: 1
    Last Post: 19th September 2008, 16:43
  4. Problem whis open device in Windows
    By Pavka in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2007, 11:13
  5. Ho to get the windows system directory with Qt4
    By rmagro in forum Qt Programming
    Replies: 4
    Last Post: 30th August 2007, 14:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.