You should not enumerate devices by using registry keys directly. Registry keys do not contain the required information to enumerate installed devices on the system. This information, such as whether the device is actually present or is a phantom device (one that is not plugged in), is held by the Plug and Play (PnP) manager. The PnP manager also performs additional filtering of registry information.
To enumerate installed devices safely, follow these steps:
Use SetupDiGetClassDevs or SetupDiGetClassDevsEx to retrieve information for a set of devices that belong to a specified device setup class. To retrieve information only for devices that are present in the system, set DIGCF_PRESENT in the Flags parameter.
Use SetupDiEnumDeviceInfo to enumerate the devices in the set.