title: Can the physical USB port be identified programmatically for a device in Windows?
body: <p>I have a USB device that enumerates with a different interface, VID, PID and serial number when commanded to do so, and I'd like to keep track of the physical device after this change occurs. My thought was to track it by its hub and port location.</p>
  
  <p>The <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394354(v=vs.85)" rel="nofollow noreferrer">Win32_PnPSignedDriver</a> class has a "Location" field that seemed perfect (e.g. <code>Port_#0001.Hub_#0010</code>), but it only contains the location of the device when the driver was first loaded. Plugging the hardware into a different port does not update that field.</p>
  
  <p>However, the information is available somewhere because there is a "Location information" field under the "Details" tab when viewing the device via the Device Manager. Can this information be retrieve through <a href="https://docs.microsoft.com/en-us/windows/win32/wmisdk/querying-wmi" rel="nofollow noreferrer">WMI queries</a> or some other method? Is there a better approach to solving this problem?</p>
  
  <p><strong>EDIT:</strong> I know this sounds like a strange scenario. The microcontroller in these devices contains a ROM that enumerates as a CDC device (i.e. serial port) and allows programming. During manufacturing, it would be beneficial to track a device as it changes between the manufacturer's ROM (unique VID/PID/serial number) and my custom firmware interface (different VID/PID/serial number).</p>