Microsoft KB Archive/259697

{|
 * width="100%"|

HOWTO: Force Reenumeration of a Device Tree From an Application

 * }

Q259697

-

The information in this article applies to:


 * Microsoft Windows 2000 Driver Development Kit (DDK)

-

SUMMARY
This article demonstrates how to force reenumeration of a device and all it's children by using the CM_Reenumerate_DevNode function. Reenumeration is required if you want to programmatically reenumerate devices on certain legacy buses such as Serial, which cannot detect Plug and Play devices.

MORE INFORMATION
The following code snippet shows you how to reenumerate the entire device tree. This is the programmatic equivalent of clicking the Scan For Hardware Changes menu item in the Device Manager.

BOOL ScanForHardwareChanges {   DEVINST     devInst; CONFIGRET  status; //    // Get the root devnode. //    status = CM_Locate_DevNode(&devInst, NULL, CM_LOCATE_DEVNODE_NORMAL); if (status != CR_SUCCESS) { printf(&quot;CM_Locate_DevNode failed: %x\n&quot;, status); return FALSE;

}   status = CM_Reenumerate_DevNode(devInst, 0); if (status != CR_SUCCESS) { printf(&quot;CM_Reenumerate_DevNode failed: %x\n&quot;, status));       return FALSE;    }

return TRUE; }

The preceding function results in IRP_MN_QUERY_DEVICE_RELATIONS (BusRelations) IRP being sent to all the devices in the device tree starting at root. This operation takes a few seconds to complete.

Instead of scanning the entire tree, you can cause a specific bus device and all it's children to be reenumerated if you have a handle to it's device instance. For additional information about how to retrieve a device instance handle of a particular device by using SetupDi API calls, click the article number below to view the article in the Microsoft Knowledge Base:

"Q259695 HOWTO: Enumerate Hardware Devices by Using SetupDi Calls"

The Config Manager APIs that require Device Instance Handle can use the DevInst value of the SP_DEVINFO_DATA structure returned by the SetupDiEnumDeviceInfo/SetupDiGetDeviceInterfaceDetail function.