Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Get USB attached Devices ' name using setupDi calls ?

How to Get USB attached Devices ' name using setupDi calls ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jochen Arndt

    When already using Setup API functions, call one that accepts a pointer to a SP_DEVINFO_DATA structure (e.g. SetupDiGetDeviceInterfaceDetail() or SetupDiEnumDeviceInfo()). Then call SetupDiGetDeviceRegistryProperty() passing the structure to get the SPDRP_FRIENDLYNAME property which contains the name as shown by Windows. If that fails, you can fallback to get the SPDRP_DEVICEDESC property.

    0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #3

    Thanks For your Reply. I tried Friendlyname,it is returning NULL. then I tried DeviceDesc , it is returning "USB PRINTING SUPPORT " for each USB connected Printer. I tried by passing SPDRP_MFG even, it is returning Microsoft. Any other way to get name so, I can differentiate. Thanks & Regards Y

    J 1 Reply Last reply
    0
    • 0 002comp

      Thanks For your Reply. I tried Friendlyname,it is returning NULL. then I tried DeviceDesc , it is returning "USB PRINTING SUPPORT " for each USB connected Printer. I tried by passing SPDRP_MFG even, it is returning Microsoft. Any other way to get name so, I can differentiate. Thanks & Regards Y

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #4

      It seems that you have enumerated the generic Microsoft USB printing support devices. You should look up the specific printers instead which usually provide a friendly name. If that did not provide the device path, you must perform two enumerations and compare common data (e.g. the hardware ID).

      0 1 Reply Last reply
      0
      • J Jochen Arndt

        It seems that you have enumerated the generic Microsoft USB printing support devices. You should look up the specific printers instead which usually provide a friendly name. If that did not provide the device path, you must perform two enumerations and compare common data (e.g. the hardware ID).

        0 Offline
        0 Offline
        002comp
        wrote on last edited by
        #5

        Ahh, But I used Class ID #define CLSID_STR_WEIUSB (L"{28D78FAD-5A12-11D1-AE5B-0000F803A8C2}") to get List of USB Printer Devices. I tried one another too #define CLSID_STR_WEIUSB1 (L"{A5DCBF10-6530-11D2-901F-00C04FB951ED}") but this one was not showing some of printers while Enumerating. Give me some Idea.How can I look up specific printers only and their Friendlynames? Regards Y

        J 1 Reply Last reply
        0
        • 0 002comp

          Ahh, But I used Class ID #define CLSID_STR_WEIUSB (L"{28D78FAD-5A12-11D1-AE5B-0000F803A8C2}") to get List of USB Printer Devices. I tried one another too #define CLSID_STR_WEIUSB1 (L"{A5DCBF10-6530-11D2-901F-00C04FB951ED}") but this one was not showing some of printers while Enumerating. Give me some Idea.How can I look up specific printers only and their Friendlynames? Regards Y

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #6

          Those IDs seem to belong to specific devices. It is often difficult to get the proper GUID. See System-Defined Device Setup Classes[^] for a list of GUIDs. You may try the Printers GUID from that list and if that does not find all try also the USB Devices GUID.

          0 1 Reply Last reply
          0
          • J Jochen Arndt

            Those IDs seem to belong to specific devices. It is often difficult to get the proper GUID. See System-Defined Device Setup Classes[^] for a list of GUIDs. You may try the Printers GUID from that list and if that does not find all try also the USB Devices GUID.

            0 Offline
            0 Offline
            002comp
            wrote on last edited by
            #7

            I tried system Defined specific printer GUID and USB GUID too. Printer = {4d36e979-e325-11ce-bfc1-08002be10318} USB = {88BAE032-5A81-49f0-BC3D-A4FF138216D6} but in this case it is not providing any device while enumerating. Y

            J 1 Reply Last reply
            0
            • 0 002comp

              I tried system Defined specific printer GUID and USB GUID too. Printer = {4d36e979-e325-11ce-bfc1-08002be10318} USB = {88BAE032-5A81-49f0-BC3D-A4FF138216D6} but in this case it is not providing any device while enumerating. Y

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #8

              What are the other parameters passed to SetupDIGetClassDevs()? Maybe this link may also help you: http://stackoverflow.com/questions/10651949/figuring-which-printer-name-corresponds-to-which-device-id[^]. For specific printers you may also get the GUID from the INF file of the printer. But this may again provide no friendly name.

              0 1 Reply Last reply
              0
              • 0 002comp

                hello Friends I am accessing USB Devices through SetupDiCalls. I am able to get USb printers'Device Path to communicate with them and its working fine. I want to know that How can I access their name also using SetuDiCalls so that I can differentiate between USB Printer Devices to with whom I have to communicate. I tried EnumPrinters to get Printers name but that doesn't provide device Path for which we needed to pass to createFile fn for communication with USB Printer. And Nothing else I found common between ENumprinter returns or setupDicalls so that I will access from their. Any Ideas ? Thanks & Regards Y

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #9

                Look at handling plug an play in applications. The DDK has a ection on it, and it gives a lot of detail on device enumeration.

                ============================== Nothing to say.

                1 Reply Last reply
                0
                • J Jochen Arndt

                  What are the other parameters passed to SetupDIGetClassDevs()? Maybe this link may also help you: http://stackoverflow.com/questions/10651949/figuring-which-printer-name-corresponds-to-which-device-id[^]. For specific printers you may also get the GUID from the INF file of the printer. But this may again provide no friendly name.

                  0 Offline
                  0 Offline
                  002comp
                  wrote on last edited by
                  #10

                  I am using it like this

                  #define CLSID_STR_WEIUSB1 (L"{A5DCBF10-6530-11D2-901F-00C04FB951ED}")

                  GUID DevClass; // CLSID holder for the WEIUSB device class

                  CLSIDFromString(CLSID_STR_WEIUSB1, &DevClass);

                  SetupDiGetClassDevs(
                  &DevClass, // Only get WEIUSB devices
                  NULL, // Not specific to any bus
                  NULL, // Not associated with any window
                  DIGCF_DEVICEINTERFACE + DIGCF_PRESENT

                  0 J 2 Replies Last reply
                  0
                  • 0 002comp

                    I am using it like this

                    #define CLSID_STR_WEIUSB1 (L"{A5DCBF10-6530-11D2-901F-00C04FB951ED}")

                    GUID DevClass; // CLSID holder for the WEIUSB device class

                    CLSIDFromString(CLSID_STR_WEIUSB1, &DevClass);

                    SetupDiGetClassDevs(
                    &DevClass, // Only get WEIUSB devices
                    NULL, // Not specific to any bus
                    NULL, // Not associated with any window
                    DIGCF_DEVICEINTERFACE + DIGCF_PRESENT

                    0 Offline
                    0 Offline
                    002comp
                    wrote on last edited by
                    #11

                    I found another fn but I don't know it is useful or am I using it Wrong ? SetupDiOpenDeviceInterfaceRegKey

                    Passing SP_DEVICE_INTERFACE_DATA DevNode which we Get from SetupDiEnumDeviceInterfaces

                    HKEY hKey = SetupDiOpenDeviceInterfaceRegKey(hDevInfoSet,&DevNode,0,KEY_READ);
                    RegQueryValueEx(hKey,_T("Port"),NULL,NULL,(LPBYTE)buf,&dwBufSize);

                    But When I tried buf is coming NULL always. Is it Right way to find from resitry? Regards Y

                    1 Reply Last reply
                    0
                    • 0 002comp

                      I am using it like this

                      #define CLSID_STR_WEIUSB1 (L"{A5DCBF10-6530-11D2-901F-00C04FB951ED}")

                      GUID DevClass; // CLSID holder for the WEIUSB device class

                      CLSIDFromString(CLSID_STR_WEIUSB1, &DevClass);

                      SetupDiGetClassDevs(
                      &DevClass, // Only get WEIUSB devices
                      NULL, // Not specific to any bus
                      NULL, // Not associated with any window
                      DIGCF_DEVICEINTERFACE + DIGCF_PRESENT

                      J Offline
                      J Offline
                      Jochen Arndt
                      wrote on last edited by
                      #12

                      The GUID you are using is GUID_DEVINTERFACE_USB_DEVICE[^]. You should use this or a similar name when not using the predefined one. Using this GUID, you are enumerating the raw USB devices which may not provide the user friendly name. You also may have a look at the USBView sample application[^]. To check if there is any entry for your printers with the user friendly name, enumerate all devices (GUID NULL, DIGCF_ALLCLASSES) and compare the hardware ID or other properties with those found enumerating the raw devices.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups