How To Force Reenumeration of a Device Tree From an Application

Article translations Article translations
Article ID: 259697 - View products that this article applies to.
This article was previously published under Q259697
Expand all | Collapse all

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("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.

REFERENCES

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

Properties

Article ID: 259697 - Last Review: February 12, 2007 - Revision: 2.3
APPLIES TO
  • Microsoft Win32 Device Driver Kit for Windows 2000
  • Microsoft Windows XP Driver Development Kit
Keywords: 
kbhowto kbwdm KB259697

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com