Windows驱动开发学习记录 根据DeviceObject获取设备名称和硬件ID

  • 获取设备名称 
POBJECT_NAME_INFORMATION pName = (POBJECT_NAME_INFORMATION)ExAllocatePoolWithTag(NonPagedPool, 1024, 'name');
if (pName)
{
    ntStatus = ObQueryNameString(pPhysicalDeviceObject, pName, 1024, &ulReturn);
    if (NT_SUCCESS(ntStatus))
    {
        KDPRINT("【USBFilter】", "Attach Device Name is :%wZ\r\n", &pName->Name);
    }
    ExFreePoolWithTag(pName, 'name');
}
  • 获取设备ID(获取结果如 USB\VID_15AD&PID_0770&REV_0000)
PUCHAR pPropertyBuffer = NULL;
pPropertyBuffer = (PUCHAR)ExAllocatePoolWithTag(PagedPool, ulBufferLength, 'pro');
if (pPropertyBuffer)
{
    ntStatus = IoGetDeviceProperty(pPhysicalDeviceObject, DevicePropertyHardwareID, ulBufferLength, pPropertyBuffer, &ulBufferLength);
    if (NT_SUCCESS(ntStatus))
    {
        KDPRINT("【USBFilter】", "Hardware Id is %ws\r\n", pPropertyBuffer);
    }
    ExFreePoolWithTag(pPropertyBuffer, 'pro');
}
  • 结果如图

 

posted @ 2023-05-24 17:04  禁锢在时空之中的灵魂  阅读(157)  评论(0编辑  收藏  举报