How To Force Reenumeration of a Device Tree From an Application


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;

// Get the root devnode.

status = CM_Locate_DevNode(&devInst, NULL, CM_LOCATE_DEVNODE_NORMAL);

if (status != CR_SUCCESS) {
printf("CM_Locate_DevNode failed: %x\n", status);
return FALSE;


status = CM_Reenumerate_DevNode(devInst, 0);

if (status != CR_SUCCESS) {
printf("CM_Reenumerate_DevNode failed: %x\n", 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:

259695 How To 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.


For more information about Config Manager API calls, refer to the Windows 2000 DDK documentation.

Artikelnummer: 259697 – Letzte Überarbeitung: 12.02.2007 – Revision: 1