I just wasted 4 hours due to a rather stupid bug in Windows Mobile (and maybe Windows CE). For future reference, in case anyone else has the same problem.
Any subkey of:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn]
cannot be deleted once created and the device is restarted.
This will call cause all sorts of havoc, including causing CAB uninstalls to fail. The reason for this, you see is if you look at the very subtle text for DeleteKey in MSDN:
”An application cannot call this function for a key that an application currently has open.”
Hmm, now let’s see.. what application has HKLM\Drivers\BuiltIn always open? …Device.exe! Oh hmm, so we can’t exactly tell device.exe to close the key… we can’t close device.exe … and we can’t even do anything to the registry before device.exe loads… looks like we’re pretty much screwed.
but wait… Maybe we can get a handle from device.exe… We can, with OpenDeviceKey, but we can’t do anything with it since we need the handle to HKLM\Drivers\Builtin, not the subkey.
So, unless you want your key on the device for a very long time, you should install your driver as a service, activate it manually… which kind of defeats the purpose of a driver…
Alternatively, you can just delete the values… but you’ll have to leave the empty key.. doesn’t seem like the right way to go either… Besides, if you put it in a cab, the cab will be forever uninstallable, as wceload.exe will just give up when it can’t delete the key. But don’t let me get started on wceload.exe and unload.exe… You’ll just get some stupid cryptic error message that your uninstall was unsuccessful.
So come on Microsoft – please add DeleteDevice or something… what if some malicious program were to exploit this? Also, please fix wceload, it… really needs an upgrade.