Removing non-present hardware with Devcon

automated-installautomation

I'm automating the removal of a USB printer from machines with Windows XP SP3.
To do this, I'm using Microsoft's Devcon Utility.

Running the command:

devcon findall *hp*

Returns:

USBPRINT\HEWLETT-PACKARDHP_LASERJET_PROFESSIONAL_P1606DN\7&8885729&0&USB001: HP
LaserJet Professional P1606dn
1 matching device(s) found.

Running the command:

devcon remove *USBPRINT*

Returns:

No devices removed.

I've tried multiple combinations of the Hardware ID and wildcards with no luck.
Plugging the device in to the computer and running the remove command mentioned above removes the hardware.

The issue comes from me using devcon piped to find to determine if the device is plugged in so that it can be automatically configured. If I can't remove it, it will be detected by my script even if it isn't plugged in.

I've tested this with multiple USB printers and one USB mouse, all exhibit the same behavior, which leads me to believe this is normal behavior for Devcon.

Is there a workaround? How do I remove hardware entries that are no longer connected?

Best Answer

Devcon does work. You just need to make sure you are targeting the right version of devcon for your operation system.

Take a look at this link http://freneticrapport.blogspot.com/2011/05/windows-hiddennot-connected-device.html.

For installing the correct devcon version for your OS:

  • Install the Windows Driver Kit
  • Go to Start -> Programs -> Development Kits -> WDK XXXX -> Build Environments -> Windows [Target] -> Windows [Target] Free Build Environment, replacing [Target] with the appropriate version of Windows you are building for.
  • Go to the src\setup\devcon folder in the WDK install directory and run: build -ceZ

You can then remove the device with the following command:

devcon remove "@PCI\VEN_1000&DEV_0060&SUBSYS_1F0C1028&REV_04\4&10333E29&0&0030"

Take note of the quotes and @ symbol as these are required to allow hidden devices to be removed.