0

I'm doing a bit of driver programming and I have a PNP driver for a pseudo-device that has it's own custom device setup class. The driver is a pseudo-bus enumerator and creates pseudo devices, not unlike the toaster example.

Anyways, I have a whole lot of old, unneeded entries in HKLM\SYSTEM\CurrentControlSet\Enum now. Is there some nice utility for removing old device enumerations in there? I don't seem to be able to do it with devcon or pnputil. I can delete it manually, but that's really tedious given that only SYSTEM has full control privileges over much of what's in Enum.

Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
  • The usual approach is to do your testing on some sort of virtual machine, which you can wipe and reload whenever you like. – Harry Johnston Apr 23 '14 at 00:15
  • What do you do when you need to talk to real hardware? – Ted Middleton Apr 24 '14 at 00:12
  • Same thing, but with a physical machine. :-) Oh, if you're talking about a USB device it should usually be possible to connect it to your VM, and I guess you can do some of the testing in that setup, but of course you also need to test on at least one physical machine. The key point is that the machine can be wiped and reloaded as often as necessary. (Anything you might do to remove the old device enumerations, or even if you just ignore them, has the potential to interfere with future testing. The only robust solution is a reinstall.) – Harry Johnston Apr 24 '14 at 00:22
  • (Of course, that doesn't mean that there isn't an existing solution, and it might well be reliable enough for your purposes, depending on your situation.) – Harry Johnston Apr 24 '14 at 00:24
  • Oh, perhaps I should mention `sysprep` as an option. The main problem with that is that you can only sysprep any given instance of Windows a fixed number of times - 4 or 5, IIRC, so it only postpones the problem. – Harry Johnston Apr 24 '14 at 00:26
  • The reason that `devcon remove` isn't working is because devcon hardcodes the `DIGCF_PRESENT` flag, and your old unneeded devices are not currently present. As [the `devcon` source code is publicly available](http://code.msdn.microsoft.com/windowshardware/DevCon-Sample-4e95d71c), would you be interested in compiling your own version that removes the flag? Hint: start with the `cmdRemove` function. – Jeffrey Tippet Apr 24 '14 at 02:46
  • Ah yes - absolutely! I was pretty sure that there had to be a setup api function to do this - USBDeview is able to remove those Enum'd devices so it can't be impossible. – Ted Middleton Apr 24 '14 at 02:50
  • Perfect - it works! I knew there had to be something in the Setup api that would do this. devcon calls SetupDiSetClassInstallParams() with DIF_REMOVE or failing that SetupDiCallClassInstaller(). Thank you! Repost your suggestion as an answer and I'll mark it as such. – Ted Middleton Apr 24 '14 at 03:17
  • Well I can't say "no" to StackOverflow points. Duly reposted. – Jeffrey Tippet Apr 24 '14 at 21:51

1 Answers1

1

The reason that devcon remove isn't working is because devcon hardcodes the DIGCF_PRESENT flag, and your old unneeded devices are not currently present. As the devcon source code is publicly available, you can compile your own version that removes the flag.

Hint: start looking in the cmdRemove function.

Jeffrey Tippet
  • 3,146
  • 1
  • 14
  • 15