none
Getting the Driver Details (inf file name) using SetupDiGetDriverInfoDetail is not returning correct inf file name.

    Question

  • Actually I have a barcode scanner. on Windows 10 we have two drivers by default. When I connected to a windows-10 machine it will automatically act as POS HID Barcode scanner (INF File name is: hidscanner.inf). with this driver we have issues. so I manually changed the driver to HID Interface device (INF File name is: input.inf). 

    When I use SetupDiGetDriverInfoDetail() to get the inf file name, In both the cases i am getting input.inf only.

    Can anyone suggest me what is the reason for it. Is there any way I can differentiate which driver is configured currently for my Barcode scanner using any API?

    Wednesday, May 15, 2019 11:27 AM

All replies

  • How did you "manually change the driver"?

    SetupDiGetDriverInfoDetail uses information that is stashed in the registry but isn't otherwise used by the system.  It isn't always updated when you make low-level changes.  Try using SetupDiGetDeviceRegistryProperty and fetch the service name, SPDRP_SERVICE.  That will tell you which service is actually registered.  Input.inf should assign "hidusb", while hidscanner.inf assigns "wudfrd", since it is a UMDF driver.

    Note, however, that this only says what is configured.  If you load the device then change the service in the registry, that doesn't immediately force the device to restart.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, May 15, 2019 6:26 PM
  • Hi Robert,

    Thanks for your reply and for the information.

    To change the driver i am following the steps mentioned below:

    1. Go into the Device Manager.
    2. Find the category "POS Barcode Scanner", expand it and double click on "POS HID Barcode scanner".
    3. Click the "Driver" tab and then the "Update Driver..." button.
    4. Click "Browse my computer for driver software".
    5. Click "Let me pick from a list of device drivers on my computer".
    6. There should now be two compatible drivers shown. One is the already active and malfunctioning "POS HID Barcode scanner" and the other is the generic "HID-compliant device" driver. Choose "HID-compliant device" and click "Next" and then "Close".
    7. Remaining on the properties page for the scanner, click the "Details" tab and choose "Hardware Ids" from the dropdown list. Write down the VID and PID values shown, for example VID_0404 and PID_0427.

    I checked by using SetupDiGetDeviceRegistryProperty and fetch the service name, SPDRP_SERVICE., but for both the drivers i am getting "hidusb" only.

    Let me know if i have to do anything to reflect this.

    "If you load the device then change the service in the registry" - This is the statement suggested by you. Change in the registry means may I know what is the exact path for the registry to change.

    Thanks in advance.

    Regards,

    Sanjay.

    Thursday, May 16, 2019 4:22 AM
  • Post your code. Also look in setupapi.dev.log when you change the drivers in device manager and see which INF and service is actually installed

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, May 16, 2019 3:22 PM
  • Hello see the sample code I am using and let me know if there is anything wrong in the code to get the driver name.

    LPTSTR GetDeviceStringProperty(__in HDEVINFO Devs, __in PSP_DEVINFO_DATA DevInfo, __in DWORD Prop)
    {
        LPTSTR buffer;
        DWORD size;
        DWORD reqSize;
        DWORD dataType;
        DWORD szChars;

        size = 1024; // initial guess
        buffer = new TCHAR[(size/sizeof(TCHAR))+1];
        if(!buffer) {
            return NULL;
        }
        while(!SetupDiGetDeviceRegistryProperty(Devs,DevInfo,Prop,&dataType,(LPBYTE)buffer,size,&reqSize)) {
            if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
                goto failed;
            }
            if(dataType != REG_SZ) {
                goto failed;
            }
            size = reqSize;
            delete [] buffer;
            buffer = new TCHAR[(size/sizeof(TCHAR))+1];
            if(!buffer) {
                goto failed;
            }
        }
        szChars = reqSize/sizeof(TCHAR);
        buffer[szChars] = TEXT('\0');
        return buffer;

    failed:
        if(buffer) {
            delete [] buffer;
        }
        return NULL;
    }


    LPTSTR GetDeviceDescription(__in HDEVINFO Devs, __in PSP_DEVINFO_DATA DevInfo)
    {
        LPTSTR desc;
        desc = GetDeviceStringProperty(Devs,DevInfo, SPDRP_SERVICE);
        if(!desc) {
            desc = GetDeviceStringProperty(Devs,DevInfo, SPDRP_SERVICE);
            char szDesc[255] = {0};
            wcstombs(szDesc, desc, wcslen(desc));
            std::cout << szDesc;
        }
        return desc;
    }

    LPTSTR GetUBARDriverName(const TCHAR* devID)
    {
        HDEVINFO devs = INVALID_HANDLE_VALUE;
        IdEntry * templ = NULL;
        int failcode = EXIT_FAIL;
        int retcode;
        DWORD devIndex;
        SP_DEVINFO_DATA devInfo;
        SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
        BOOL match = FALSE;
        GUID cls;
        DWORD numClass = 0;
        int argIndex = 0;

        templ = new IdEntry[1];
        if (!templ)
        {
            return NULL;
        }

        templ[0] = GetIdType(devID);

        devs = SetupDiGetClassDevsEx(NULL,
            NULL,
            NULL,
            DIGCF_ALLCLASSES | DIGCF_PRESENT,
            NULL,
            NULL,
            NULL);

        if (devs == INVALID_HANDLE_VALUE)
        {
            return NULL;
        }


        if (templ[0].InstanceId)
        {
            SetupDiOpenDeviceInfo(devs, templ[0].String, NULL, 0, NULL);
        }

        devInfoListDetail.cbSize = sizeof(devInfoListDetail);
        if (!SetupDiGetDeviceInfoListDetail(devs, &devInfoListDetail))
        {
            return NULL;
        }


        devInfo.cbSize = sizeof(devInfo);
        for (devIndex = 0; SetupDiEnumDeviceInfo(devs, devIndex, &devInfo); devIndex++)
        {
            for (argIndex = 0, match = FALSE; (argIndex < 1) && FALSE == match; argIndex++)
            {
                TCHAR devID1[MAX_DEVICE_ID_LEN] = { 0 };
                LPTSTR *hwIds = NULL;
                LPTSTR *compatIds = NULL;
                //
                // determine instance ID
                //
                if (CM_Get_Device_ID_Ex(devInfo.DevInst, devID1, MAX_DEVICE_ID_LEN, 0, devInfoListDetail.RemoteMachineHandle) != CR_SUCCESS)
                {
                    devID1[0] = TEXT('\0');
                }

                if (templ[0].InstanceId)
                {
                    //
                    // match on the instance ID
                    //
                    if (WildCardMatch(devID1, templ[0]))
                    {
                        match = TRUE;
                    }
                }
                else
                {
                    //
                    // determine hardware ID's
                    // and search for matches
                    //
                    hwIds = GetDevMultiSz(devs, &devInfo, SPDRP_HARDWAREID);
                    compatIds = GetDevMultiSz(devs, &devInfo, SPDRP_COMPATIBLEIDS);

                    if (WildCompareHwIds(hwIds, templ[0]) ||
                        WildCompareHwIds(compatIds, templ[0]))
                    {
                        match = TRUE;
                    }
                }

                DelMultiSz(hwIds);
                DelMultiSz(compatIds);
            }

            if (match)
            {
                LPTSTR desc;
                desc = GetDeviceDescription(devs, &devInfo);
                if (!desc)
                    delete[] desc;
                return desc;
            }
        }
    }


    GetUBARDriverName(TEXT(""*VID_0404&PID_0427*""));

    When I install the driver using device manager, in setupapi.dev.log I can see the corresponding inf file is executed correctly and the installation is success. After installation i can see enumeration of my device perfectly.

    If I install HID Driver then input.inf file is used in setup api logs and the Device enumerated and showed under HID Devices list.

    If I install HID POS Driver then hidscanner.inf file is used in setup api logs and the Device enumerated and showed under HIS POS Barcode Scanner list.

    But at any time I am seeing the driver entries in the registry like below:

    for HID Driver: Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\USB\VID_0404&PID_0427

    for POS Driver: Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\HID\VID_0404&PID_0427\

    Irrespective of the driver installed, i am seeing both the registry keys available and when i use SetupDiGetDeviceRegistryProperty () or SetupDiGetDriverInfoDetail () it returns only input.inf driver details only. 

    Can anyone suggest what is the problem here?

    Friday, May 17, 2019 5:13 AM
  • Remember that the Enum tree contains every device your computer has ever seen, including those that are no longer plugged in.  The PRESENCE of a registry key tells you nothing.

    The USB\VID_0404&PID_0437 key is created by the USB drivers.  Those drivers then create HID\VID_0404&PID_0437, which get handled by other drivers.  If there are multiple HID collections, each one gets a separate subkey under the HID\xxx key, and each of those gets its own driver.  The service for the USB\xxx device should probably be "hidusb".  The service for the HID\xxx device should be "kbdhid" for the standard device.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Friday, May 17, 2019 10:08 PM
  • Hi Tim,

    Thanks for the information.

    Could you please suggest us how can I proceed further to get the correct driver information.

    Regards,

    Sanjay.

    Saturday, May 18, 2019 1:48 PM
  • Why do you query for hardware ID, rather than Class? or Service? or INF name, INF section?

    All these properties are available.

    -- pa

    Saturday, May 18, 2019 10:18 PM
  • I think you're doing the right thing.  What, exactly, are the service names you read from your two devices with your two different drivers?

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Sunday, May 19, 2019 4:59 AM
  • Hi Robert,

    Thanks for the information. I have only one device but the drivers are different(Both are microsoft one only).

    Whenever I query for the driver name it is always giving "hidusb". when I install the driver using hidscanner.inf also i am getting "hidusb" only. In the hidscanner.inf scenario I am expecting the driver name as "wudfrd", But i am not getting that one.

    Regards,

    Sanjay.

    Sunday, May 19, 2019 4:23 PM
  • > I have only one device.

    No, you don't.  Your own code showed you that, didn't it?  You have a device in the Enum\USB tree, and you have one in the Enum\HID tree.  BOTH of those are devices and drivers supporting your device.

    Look in the INF file for the hidscanner.inf.  EXACTLY what devices does it match?  Is it the USB\VID_xxxx or is it HID\VID_xxxx?


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Monday, May 20, 2019 5:50 AM