Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:50:04+00:00 2026-06-04T07:50:04+00:00

I am attempting to retrieve the Friendly name for a USB device. The code

  • 0

I am attempting to retrieve the “Friendly name” for a USB device. The code sample I found uses SetupDiGetDeviceProperty, and works wonderfully on Windows Vista and later. Unfortunately I also have to support Windows XP. Is there an alternate API call, available in XP, that would allow me to retrieve the same information?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:50:04+00:00Added an answer on June 4, 2026 at 7:50 am

    you can use the Win32_PnPEntity WMI class to get most of the information returned by the SetupDiGetDeviceProperty function.

    Try this C++ sample

    #include "stdafx.h"
    #define _WIN32_DCOM
    #include <iostream>
    using namespace std;
    #include <comdef.h>
    #include <Wbemidl.h>
    # pragma comment(lib, "wbemuuid.lib")
    
    //CREDENTIAL structure
    //http://msdn.microsoft.com/en-us/library/windows/desktop/aa374788%28v=vs.85%29.aspx
    #define CRED_MAX_USERNAME_LENGTH            513
    #define CRED_MAX_CREDENTIAL_BLOB_SIZE       512
    #define CREDUI_MAX_USERNAME_LENGTH CRED_MAX_USERNAME_LENGTH
    #define CREDUI_MAX_PASSWORD_LENGTH (CRED_MAX_CREDENTIAL_BLOB_SIZE / 2)
    
    #pragma argsused
    int main(int argc, char* argv[])
    {
        wchar_t pszName[CREDUI_MAX_USERNAME_LENGTH+1] = L"user";
        wchar_t pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1]  = L"password";
        BSTR strNetworkResource;
        //To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
        bool localconn = true;  
        strNetworkResource = localconn ?  L"\\\\.\\root\\CIMV2" : L"\\\\remote--machine\\root\\CIMV2";
    
        COAUTHIDENTITY *userAcct =  NULL ;
        COAUTHIDENTITY authIdent;
    
        // Initialize COM. ------------------------------------------
    
        HRESULT hres;
        hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
        if (FAILED(hres))
        {
            cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            cout << "press enter to exit" << endl;
            cin.get();      
            return 1;                  // Program has failed.
        }
    
        // Set general COM security levels --------------------------
    
        if (localconn)
            hres =  CoInitializeSecurity(
                NULL,
                -1,                          // COM authentication
                NULL,                        // Authentication services
                NULL,                        // Reserved
                RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
                RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
                NULL,                        // Authentication info
                EOAC_NONE,                   // Additional capabilities
                NULL                         // Reserved
                );
        else
            hres =  CoInitializeSecurity(
                NULL,
                -1,                          // COM authentication
                NULL,                        // Authentication services
                NULL,                        // Reserved
                RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
                RPC_C_IMP_LEVEL_IDENTIFY,    // Default Impersonation
                NULL,                        // Authentication info
                EOAC_NONE,                   // Additional capabilities
                NULL                         // Reserved
                );
    
        if (FAILED(hres))
        {
            cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();      
            return 1;                    // Program has failed.
        }
    
        // Obtain the initial locator to WMI -------------------------
    
        IWbemLocator *pLoc = NULL;
        hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
    
        if (FAILED(hres))
        {
            cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            CoUninitialize();       
            cout << "press enter to exit" << endl;
            cin.get();      
            return 1;                 // Program has failed.
        }
    
        // Connect to WMI through the IWbemLocator::ConnectServer method
    
        IWbemServices *pSvc = NULL;
    
        if (localconn)  
            hres = pLoc->ConnectServer(
                 _bstr_t(strNetworkResource),      // Object path of WMI namespace
                 NULL,                    // User name. NULL = current user
                 NULL,                    // User password. NULL = current
                 0,                       // Locale. NULL indicates current
                 NULL,                    // Security flags.
                 0,                       // Authority (e.g. Kerberos)
                 0,                       // Context object
                 &pSvc                    // pointer to IWbemServices proxy
                 );
        else
            hres = pLoc->ConnectServer(
                _bstr_t(strNetworkResource),  // Object path of WMI namespace
                _bstr_t(pszName),             // User name
                _bstr_t(pszPwd),              // User password
                NULL,                // Locale
                NULL,                // Security flags
                NULL,                // Authority
                NULL,                // Context object
                &pSvc                // IWbemServices proxy
                );
    
        if (FAILED(hres))
        {
            cout << "Could not connect. Error code = 0x" << hex << hres << endl;    
            cout << _com_error(hres).ErrorMessage() << endl;
            pLoc->Release();
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();          
            return 1;                // Program has failed.
        }
    
        cout << "Connected to root\\CIMV2 WMI namespace" << endl;
    
        // Set security levels on the proxy -------------------------
        if (localconn)
            hres = CoSetProxyBlanket(
               pSvc,                        // Indicates the proxy to set
               RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
               RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
               NULL,                        // Server principal name
               RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
               RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
               NULL,                        // client identity
               EOAC_NONE                    // proxy capabilities
            );
        else
        {
            // Create COAUTHIDENTITY that can be used for setting security on proxy
            memset(&authIdent, 0, sizeof(COAUTHIDENTITY));
            authIdent.PasswordLength = wcslen (pszPwd);
            authIdent.Password = (USHORT*)pszPwd;
            authIdent.User = (USHORT*)pszName;
            authIdent.UserLength = wcslen(pszName);
            authIdent.Domain = 0;
            authIdent.DomainLength = 0;
            authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
            userAcct = &authIdent;
    
            hres = CoSetProxyBlanket(
               pSvc,                           // Indicates the proxy to set
               RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
               RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
               COLE_DEFAULT_PRINCIPAL,         // Server principal name
               RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
               RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
               userAcct,                       // client identity
               EOAC_NONE                       // proxy capabilities
            );
        }
    
        if (FAILED(hres))
        {
            cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            pSvc->Release();
            pLoc->Release();
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();      
            return 1;               // Program has failed.
        }
    
        // Use the IWbemServices pointer to make requests of WMI ----
    
        IEnumWbemClassObject* pEnumerator = NULL;
        hres = pSvc->ExecQuery( L"WQL", L"SELECT * FROM Win32_PnPEntity",
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
    
        if (FAILED(hres))
        {
            cout << "ExecQuery failed" << " Error code = 0x"    << hex << hres << endl;
            cout << _com_error(hres).ErrorMessage() << endl;
            pSvc->Release();
            pLoc->Release();
            CoUninitialize();
            cout << "press enter to exit" << endl;
            cin.get();      
            return 1;               // Program has failed.
        }
    
        // Secure the enumerator proxy
        if (!localconn)
        {
    
            hres = CoSetProxyBlanket(
                pEnumerator,                    // Indicates the proxy to set
                RPC_C_AUTHN_DEFAULT,            // RPC_C_AUTHN_xxx
                RPC_C_AUTHZ_DEFAULT,            // RPC_C_AUTHZ_xxx
                COLE_DEFAULT_PRINCIPAL,         // Server principal name
                RPC_C_AUTHN_LEVEL_PKT_PRIVACY,  // RPC_C_AUTHN_LEVEL_xxx
                RPC_C_IMP_LEVEL_IMPERSONATE,    // RPC_C_IMP_LEVEL_xxx
                userAcct,                       // client identity
                EOAC_NONE                       // proxy capabilities
                );
    
            if (FAILED(hres))
            {
                cout << "Could not set proxy blanket on enumerator. Error code = 0x" << hex << hres << endl;
                cout << _com_error(hres).ErrorMessage() << endl;
                pEnumerator->Release();
                pSvc->Release();
                pLoc->Release();
                CoUninitialize();
                cout << "press enter to exit" << endl;
                cin.get();              
                return 1;               // Program has failed.
            }
        }
    
        // Get the data from the WQL sentence
        IWbemClassObject *pclsObj = NULL;
        ULONG uReturn = 0;
    
        while (pEnumerator)
        {
            HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
    
            if(0 == uReturn || FAILED(hr))
              break;
    
            VARIANT vtProp;
    
                    hr = pclsObj->Get(L"Description", 0, &vtProp, 0, 0);// String
                    if (!FAILED(hr))
                    {
                      if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                        wcout << "Description : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                      else
                      if ((vtProp.vt & VT_ARRAY))
                        wcout << "Description : " << "Array types not supported (yet)" << endl;
                      else
                        wcout << "Description : " << vtProp.bstrVal << endl;
                    }
                    VariantClear(&vtProp);
    
                    hr = pclsObj->Get(L"DeviceID", 0, &vtProp, 0, 0);// String
                    if (!FAILED(hr))
                    {
                      if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                        wcout << "DeviceID : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                      else
                      if ((vtProp.vt & VT_ARRAY))
                        wcout << "DeviceID : " << "Array types not supported (yet)" << endl;
                      else
                        wcout << "DeviceID : " << vtProp.bstrVal << endl;
                    }
                    VariantClear(&vtProp);
    
                    hr = pclsObj->Get(L"HardwareID", 0, &vtProp, 0, 0);// String
                    if (!FAILED(hr))
                    {
                      if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                        wcout << "HardwareID : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                      else
                      if ((vtProp.vt & VT_ARRAY))
                        wcout << "HardwareID : " << "Array types not supported (yet)" << endl;
                      else
                        wcout << "HardwareID : " << vtProp.bstrVal << endl;
                    }
                    VariantClear(&vtProp);
    
                    hr = pclsObj->Get(L"Manufacturer", 0, &vtProp, 0, 0);// String
                    if (!FAILED(hr))
                    {
                      if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                        wcout << "Manufacturer : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                      else
                      if ((vtProp.vt & VT_ARRAY))
                        wcout << "Manufacturer : " << "Array types not supported (yet)" << endl;
                      else
                        wcout << "Manufacturer : " << vtProp.bstrVal << endl;
                    }
                    VariantClear(&vtProp);
    
                    hr = pclsObj->Get(L"PNPDeviceID", 0, &vtProp, 0, 0);// String
                    if (!FAILED(hr))
                    {
                      if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                        wcout << "PNPDeviceID : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                      else
                      if ((vtProp.vt & VT_ARRAY))
                        wcout << "PNPDeviceID : " << "Array types not supported (yet)" << endl;
                      else
                        wcout << "PNPDeviceID : " << vtProp.bstrVal << endl;
                    }
                    VariantClear(&vtProp);
    
    
            pclsObj->Release();
            pclsObj=NULL;
        }
    
        // Cleanup
    
        pSvc->Release();
        pLoc->Release();
        pEnumerator->Release();
        if (pclsObj!=NULL)
         pclsObj->Release();
    
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();
        return 0;   // Program successfully completed.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to retrieve the user name and client machine name of the person
I'm attempting to retrieve the current field name on a custom Sitecore field I'm
I'm attempting to retrieve data from a SolarWinds network performance database (MS SQL 2005)
I'm attempting to retrieve the value of a property from an instance of MemberExpression
When attempting to use HttpWebRequest to retrieve a page from my dev server, I
I am attempting to do the following: Retrieve a generated pdf from a web
I'm attempting to use the following sql to retrieve the total amount received, and
I am attempting to retrieve a list of objects from Entity Framework via WCF,
I am attempting to retrieve information on all the various monitors (and their adapters)
I am using windows authentication in a ASP.Net Web Application and in the code-behind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.