关于WinCE调用RegDeleteKey不能删除注册表项的问题

在写一个WinCE注册表操作的时候,调用RegDeleteKey函数却不能删除注册表项,始终返回5的错误(ACCESS DENY)。查了一下,有的说是什么权限的问题,操作的时候都是先打开注册表,如果打开成功,即调用RegDeleteKey删除此键,其实这都是不对的,经过反复查看其文档介绍,终于在一个不起眼的句子中找到了答案。下面先介绍一个此函数,直接贴原文。

RegDeleteKey (Windows CE 5.0)

Windows CE 5.0
This topic has not yet been rated Rate this topic
Send Feedback

This function recursively deletes all subkeys of a named subkey of a specified registry key.

A remote application interface (RAPI) version of this function exists, and it is called CeRegDeleteKey (RAPI).

LONG RegDeleteKey( 
  HKEY hKey, 
  LPCWSTR lpSubKey 
);
Parameters
hKey
[in] Handle to a currently open key or one of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

The key specified by the lpSubKey parameter must be a subkey of the key identified by hKey.

The access rights of this key do not affect the delete operation. 

lpSubKey
[in] Pointer to a null-terminated string specifying the name of the key to delete. This parameter cannot be NULL.
Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you callFormatMessage it could fail.

Remarks

If the function succeeds, RegDeleteKey removes the specified key from the registry. The entire key, including all of its values, is removed. An application cannot call RegDeleteKey for a key that an application currently has open.

To open the key, use the RegCreateKeyEx or RegOpenKeyEx function.

注意到文中的三句话: The access rights of this key do not affect the delete operation. 

Handle to a currently open key or one of the following predefined reserved handle values

An application cannot call RegDeleteKey for a key that an application currently has open.

就是说,键的访问权限不影响RegDeleteKey的删除操作,对于预先定义好的键值,不能在一个已经打开的键上调用RegDeleteKey,否则会报5的错误,即无需打开再删除,而是直接调用此函数删除键值。如下为例子:

要删除的键值为:

HKEY_LOCAL_MACHINE/Services/FinServ

代码为:
HKEY RootKey = HKEY_LOCAL_MACHINE;
CString strSubKey = _T("\\Services\\FinServ");
long nRet = 0;

nRet = RegDeleteKey(RootKey,strSubKey);

if(nRet== ERROR_SUCCESS)
{
//删除成功
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值