How to get Device Instance Path from Windows kernel driver?

好久不见. 提交于 2019-12-24 04:32:42

问题


Take a look at this example: a USB device in Windows 7 is reported to have Device instance path(DevinstPath) USB\VID_1EAB&PID_0501\7&25C389C1&0&1 and I know exactly that it corresponds to the so-called hardware-key(hwkey) in registry.

Now my question is: When my KMDF driver code has WDFDEVICE handle for that USB device, how can I know its DevinstPath?

I know I can

  • send a BusQueryDeviceID to achieve the so-called device-id USB\VID_1EAB&PID_0501;
  • send a BusQueryInstanceID to achieve the so-called instance-id 1 .

But I don't know how to get the so-called "instance-path". Could some kernel guru kindly tell me how I can get that?

MSDN doc seems really vague on this!

BTW: I also realize that user-layer function SetupDiGetDeviceInstanceId actually returns the DevinstPath -- although it is named "InstanceId".


回答1:


Device instance path can be queried using DEVPKEY_Device_InstanceId, using either WdfDeviceAllocAndQueryPropertyEx or IoGetDevicePropertyData (passing the WDM physical device object)




回答2:


Device Instance id is autoincrement sequence. You can find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum in registry; Rules:NextPareneID.XXXXXXXX.N XXXXXX use UUID Calculation crc32 values(test ok) N is 1~9 Device Instance id format is N&PareneID&random's number&index

enter image description here



来源:https://stackoverflow.com/questions/44776328/how-to-get-device-instance-path-from-windows-kernel-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!