Windows Mobile:
As the final step of unloading a driver, I am trying to delete the registry subkey (HKLM\Drivers\BuiltIn\XYZ) using RegDeleteKey API and it fails returning ERROR_ACCESS_DENIED code.
Below are the steps I followed:
1. FindFirstDevice
2. Stored the key and needed values for later use in case I need to reload the driver (Used RegOpenKeyEx and RegQueryValueEx APIs)
3. DeactivateDevice
4. RegCloseKey
5. RegDeleteKey
Steps 1 thru 4 work pretty fine, however, step 5 fails. Please suggest.
The reasons could be
Make sure you deleted each of the contained value pairs
You maybe trying to delete key that are not permitted to be deleted by anyone. Try changing to another key which you are able to delete for sure, and then test the code again.
You might forget to close the handle to this key (HKLM\szSubKey) elsewhere. You may create a new application and test the above code there.
If it works fine in third case, the key might be used by the system or another process so you cannot delete it.