Unable to set friendly name for device in Windows 7

In my UMDF device driver, I configured a friendly name for my device:

HRESULT CMyDevice::SetFriendlyDeviceName(WCHAR * FriendlyName)
{
    HRESULT hr = HRESULT_FROM_WIN32(ERROR_GEN_FAILURE);
    CComPtr<IWDFUnifiedPropertyStoreFactory> upsf = NULL;

    hr = m_FxDevice->QueryInterface(&upsf);
    if (SUCCEEDED(hr))
    {
        CComPtr<IWDFUnifiedPropertyStore> ups = NULL;
        WDF_PROPERTY_STORE_ROOT rs;

        RtlZeroMemory(&rs, sizeof(WDF_PROPERTY_STORE_ROOT));
        rs.LengthCb = sizeof(WDF_PROPERTY_STORE_ROOT);
        rs.RootClass = WdfPropertyStoreRootClassHardwareKey;
        rs.Qualifier.HardwareKey.ServiceName = NULL;

        hr = upsf->RetrieveUnifiedDevicePropertyStore(&rs, &ups);
        if (SUCCEEDED(hr))
        {
            ULONG len = ((ULONG)wcslen(FriendlyName) * sizeof(WCHAR)) + sizeof(WCHAR);

            hr = ups->SetPropertyData(&DEVPKEY_Device_FriendlyName, 0, 0, DEVPROP_TYPE_STRING, len, FriendlyName);
            if (FAILED(hr))
                TraceEvents(TRACE_LEVEL_WARNING, TRACE_DEVICE, "Failed to set friendly name for device: %x", hr);
            else
                TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "Friendly name for device successfully set");
        }
        else
            TraceEvents(TRACE_LEVEL_WARNING, TRACE_DEVICE, "Failed to retrieve unified device property store: %x", hr);
    }
    else
        TraceEvents(TRACE_LEVEL_WARNING, TRACE_DEVICE, "Failed to retrieve unified property store factory: %x", hr);

}

      

It works in Windows 8 and 10. The problem is, it doesn't work in Windows 7 and Vista. Although I don't see any errors running the code above and it says "Friendly name for the device has been successfully set", the friendly name does not change in Device Manager. It also does not change after updating the device list. When I look into my device's storage key in the registry HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_XXXX&PID_XXXX\XXXX

, there is no value for "FriendlyName". When I add it manually, it shows up in the device manager.

+3


source to share





All Articles