Removing orphaned/phantom/non-present devices

I’m trying to figure out how to properly remove the registry-remnants of instances of our device after the driver has been uninstalled.

We have an app that installs on Windows (10) with our display driver. The app creates (software) instances of the display adapter device, and later removes them prior to exiting (“removing” the devices is accomplished by closing the handle returned by SwDeviceCreate).

Between runs of our app, it’s possible to see these “phantom” devices listed under Display Adapter in Device Manager if Show hidden devices is checked in the View menu.

When the user updates our app, the installer uninstalls the old app and driver prior to installing the new ones.

With their driver gone, these phantom devices move under the Unknown devices node in Device Manager. They can cause problems for the newer driver, so I’d like to clean them up.

In Device Manager, I just right-click on them and choose Uninstall device, but I haven’t figured out how to replicate what it’s doing in code.

I can use CM_Locate_DevNode with CM_LOCATE_DEVNODE_PHANTOM to look up my devices by device Id, and the function returns success if the phantom is there. But since these are just leftover registry stuff (no actual node in the device tree), it seems that I don’t get back a valid DEVINST.

I’m guessing that the answer involves multiple calls to something like CM_Delete_DevNode_Key (or CM_Delete_Class_Key or CM_Delete_Device_Interface_Key).

I’m a lot less optimistic about experimenting with deleting various keys from the registry. Is there some canonical reference somewhere I can look at?


Where is the leftover registry stuff: in Enum or software (Class…) branch?

I’m not actually sure. I see it in Device Manager when Show hidden devices is checked, but I don’t know how that maps back to the registry…

I can right-click on the four “phantom” devices above, and choose Uninstall device. Device Manager does something, and the phantom disappears.

Try to remove these phantom instances with devcon. If it can remove these, you have the code.
To find the instance path, right click on the device → Properties → details.

1 Like

That did it. Thanks Pavel!