The USB device location is represented by the device’s HUB identifier and the port in the HUB: Z&ZZZZZZZ&Z&A. Z&ZZZZZZZ&Z is the HUB identifier or PrefixID, and A is the port/address in the HUB (1 to 8).
In order to retrieve the device location ID, you must first retrieve the device instance ID, represented by the device type, Vendor ID, Product ID, HUB ID and port ID: USB\VID_XXXX&PID_YYYY\Z&ZZZZZZZ&Z&A.
DeviceInstanceId is returned by SetupDiGetDeviceInstanceId().

In order to detect the USB device location, do the following:

    1. Get the DriverKeyName by calling WinDriver’sWDU_GetDeviceRegistryProperty() function (orWD_GetDeviceProperty() — for v8.1.2 and below) with theWdDevicePropertyDriverKeyName registry property.


    1. Get the ClassGUID, by calling WDU_GetDeviceRegistryProperty() (orWD_GetDeviceProperty()) — in v8.1.2 and below) with theWdDevicePropertyClassGuid property.


    1. By using GetDeviceInstanceId() (see later) with the retrievedDriverKeyName and ClassGUID, get the DeviceInstanceId.


  1. From the retrieved DeviceInstanceId, get the USB device location, Z&ZZZZZZZ&Z&A.

<span style="color: #0000ff;">/*
 szDriverKeyName is returned by
 WDU_GetDeviceRegistryProperty() /
 It looks like:
 szClassGUID is returned by WDU_GetDeviceProperty.
 It looks like:

 GetDeviceInstanceId() creates a list of the device
 information for all devices of the specified class.
 The function then searches the list for the
 WinDriver device and retrieves the device instance
 ID (*pszDeviceInstanceId).

<span style="color: #cc66ff;">#include <span style="color: #ff00ff;"><windows.h>
#include <setupapi.h>
#include <string.h>


 szDriverKeyName, PTCHAR *pszDeviceInstanceId)
 <span style=”color: #0000ff;”>/* Build class GUID from szClassGUID */
 GUID guid;
 DWORD dwMemberIndex=<span style=”color: #ff00ff;”>0;
 SP_DEVINFO_DATA DeviceInfoData;
 BOOL bResult;
 DWORD dwError;
 DWORD dwPropertyBufferSize;
 PTCHAR pbPropertyBuffer;
 DWORD dwRequiredSize;
 DWORD dwPropertyRegDataType;
 HDEVINFO hDeviceInfoSet;


 *pszDeviceInstanceId = <span style=”color: #ff00ff;”>NULL;

 <span style=”color: #0000ff;”>/* Create a list of the device information for all
 devices of the specified class */
 hDeviceInfoSet = SetupDiGetClassDevs(&guid,;
 <span style=”color: #ff00ff;”>NULL, <span style=”color: #ff00ff;”>NULL, DIGCF_PRESENT);

 <span style=”color: #993300;”>if (INVALID_HANDLE_VALUE == hDeviceInfoSet)
 <span style=”color: #0000ff;”>/* Set error */
 <span style=”color: #0000ff;”>/* ……….. */
 <span style=”color: #993300;”>return FALSE;

 <span style=”color: #0000ff;”>/* Search the device information list for
 the WinDriver device */

 DeviceInfoData.cbSize = <span style=”color: #993300;”>sizeof(SP_DEVINFO_DATA);
 <span style=”color: #993300;”>do {
 <span style=”color: #0000ff;”>/* Get the next device in the list */
 bResult =
 dwMemberIndex, &DeviceInfoData);

 <span style=”color: #993300;”>if (bResult)
 dwRequiredSize = <span style=”color: #ff00ff;”>0;
 <span style=”color: #0000ff;”>/* Check if there is a driver reg path for this device */

 <span style=”color: #0000ff;”>/* First get the size only */
 bResult = SetupDiGetDeviceRegistryProperty
 <span style=”color: #ff00ff;”>NULL,
 <span style=”color: #ff00ff;”>0,

 <span style=”color: #993300;”>if (bResult && dwRequiredSize > <span style=”color: #ff00ff;”>0)
 dwPropertyBufferSize =
 dwRequiredSize + 1;

 pbPropertyBuffer =
 (TCHAR *)malloc(sizeof(TCHAR) *

 ASSERT(pbPropertyBuffer != <span style=”color: #ff00ff;”>NULL);

 <span style=”color: #0000ff;”>/* Then get this driver’s actual registry path */
 <span style=”color: #993300;”>if (SetupDiGetDeviceRegistryProperty
 <span style=”color: #0000ff;”>/* Check if the reg path is the same as in WinDriver */
 <span style=”color: #008000;”>int iResult = _tcscmp(

 <span style=”color: #993300;”>if (iResult == <span style=”color: #ff00ff;”>0)
 <span style=”color: #0000ff;”>/* This is the device we are working with
 using WinDriver */

 /* Get the device’s instance ID */

 /* First get the size only */
 dwRequiredSize = <span style=”color: #ff00ff;”>0;

 bResult =
 <span style=”color: #ff00ff;”>NULL,

 <span style=”color: #993300;”>if (bResult && dwRequiredSize)
 *pszDeviceInstanceId ==
 (TCHAR *)malloc(
 sizeof(TCHAR) *
 (dwRequiredSize + 1));

 != <span style=”color: #ff00ff;”>NULL);

 <span style=”color: #0000ff;”>/* Then get the actual device instance id */
 <span style=”color: #993300;”>if (
 dwRequiredSize + <span style=”color: #ff00ff;”>1,
 <span style=”color: #ff00ff;”>NULL))
 dwError =
 <span style=”color: #0000ff;”>/* ….. */
 <span style=”color: #993300;”>else
 delete pbPropertyBuffer;             }


 } <span style=”color: #993300;”>while(bResult && !*pszDeviceInstanceId);


 <span style=”color: #993300;”>return FALSE;