简体   繁体   English

RegDeleteKey因ERROR_ACCESS_DENIED失败

[英]RegDeleteKey fails with ERROR_ACCESS_DENIED

Windows Mobile: 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. 作为卸载驱动程序的最后一步,我尝试使用RegDeleteKey API删除注册表子项(HKLM \\ Drivers \\ BuiltIn \\ XYZ),但无法返回ERROR_ACCESS_DENIED代码。

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. 步骤1到4工作得很好,但是,第5步失败了。 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. 您可能忘记在其他位置关闭此键的句柄(HKLM \\ szSubKey)。 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. 如果在第三种情况下工作正常,则系统或其他进程可能会使用该密钥,因此您无法将其删除。

Just to update on this, I used bus IOCTL's to deactivate the device and re-activate it later when I am done with the intermediate actions that I had to perform. 为了对此进行更新,我使用总线IOCTL来停用设备,并在完成我必须执行的中间操作后重新激活它。 This way I didn't have to worry about dealing with registry deletion. 这样我就不必担心处理删除注册表了。 This is pretty neat and safe. 这非常整洁安全。 No messing up with the driver on the device, which might lead to a bad state of the system if something goes wrong while the driver was unloaded. 不要弄乱设备上的驱动程序,如果在卸载驱动程序时出现问题,可能会导致系统状态错误。 Here is a very good article on How WinCE bus drivers work . 这是关于WinCE总线驱动程序如何工作的非常好的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM