You can use SetupDiGetDeviceInstanceId
A quick test with GUID_SERENUM_BUS_ENUMERATOR =>
HDEVINFO DeviceInfoSet = SetupDiGetClassDevs(&GUID_SERENUM_BUS_ENUMERATOR, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (DWORD dwDeviceIndex = 0; SetupDiEnumDeviceInfo(DeviceInfoSet, dwDeviceIndex, &DeviceInfoData); dwDeviceIndex++)
{
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for (DWORD dwMemberIndex = 0; SetupDiEnumDeviceInterfaces(DeviceInfoSet, &DeviceInfoData, &GUID_SERENUM_BUS_ENUMERATOR, dwMemberIndex, &DeviceInterfaceData); dwMemberIndex++)
{
DWORD dwDeviceInterfaceDetailDataSize = offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA, DevicePath) + MAX_PATH * sizeof(TCHAR);
PSP_DEVICE_INTERFACE_DETAIL_DATA pDeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)new BYTE[dwDeviceInterfaceDetailDataSize];
pDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, &DeviceInterfaceData, pDeviceInterfaceDetailData, dwDeviceInterfaceDetailDataSize, NULL, NULL))
{
DWORD dwRegType;
WCHAR wsPropertyBuffer[256] = L"";
BOOL bRet = SetupDiGetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData, SPDRP_FRIENDLYNAME, &dwRegType, (BYTE*)wsPropertyBuffer, 256, NULL);
ULONG nSize = 0;
WCHAR wsInstanceId[255] = L"";
SetupDiGetDeviceInstanceId(DeviceInfoSet, &DeviceInfoData, wsInstanceId, nSize, &nSize);
bRet = SetupDiGetDeviceInstanceId(DeviceInfoSet, &DeviceInfoData, wsInstanceId, nSize, &nSize);
WCHAR wsText[255] = L"";
swprintf(wsText, L"Name : %s\r\n", wsPropertyBuffer);
OutputDebugString(wsText);
swprintf(wsText, L"InstanceId : %s\r\n", wsInstanceId);
OutputDebugString(wsText);
delete[] pDeviceInterfaceDetailData;
}
}
}