关于WinCE调用RegDeleteKey不能删除注册表项的问题
2014-03-28 23:43
225 查看
在写一个WinCE注册表操作的时候,调用RegDeleteKey函数却不能删除注册表项,始终返回5的错误(ACCESS DENY)。查了一下,有的说是什么权限的问题,操作的时候都是先打开注册表,如果打开成功,即调用RegDeleteKey删除此键,其实这都是不对的,经过反复查看其文档介绍,终于在一个不起眼的句子中找到了答案。下面先介绍一个此函数,直接贴原文。
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).
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.
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.
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)
{
//删除成功
}
RegDeleteKey (Windows CE 5.0)
Windows CE 5.0This 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 withthe 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 hasopen.
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)
{
//删除成功
}
相关文章推荐
- 关于RegDeleteKey无法删除注册表项
- 关于oracle使用delete删除的问题
- File.Delete不能删除文件的问题
- 关于delete一个派生类时调用基类定义的virtual destructor的问题
- 关于List,ArrayList中remove(object obj)方法不能删除对象问题
- 关于ajax代码包含到页面不能调用的问题
- 关于sqlserver 2005 reporting service 中的自定义代码不能调用的问题
- 关于Dalston.SR3版本的spring cloud,用feign客户端调用服务hystrix不能生效的问题
- 关于diskgenius删除所有分区后,电脑不能识别U盘的问题。
- 关于64位系统上运行32位IIS,而不能调用的ODBC获取数据的问题。
- 关于子类中不能调用基类中定义的事件问题
- 关于System.gc()解决File的Delete和DeleteOnExit()删除文件无效的问题——已解决
- 关于ModalPopup控件不能调用CS事件代码的问题
- 关于so库中的方法不能在子线程中调用的问题
- 关于Scanner调用nextInt()异常try后不能二次输入问题
- 关于uchome页面不能被iframe调用的问题,已解决!
- 关于ModalPopup控件不能调用CS事件代码的问题
- C# 删除自己new的控件是,不能直接调用控件的Dispose否则有奇怪的问题
- Android studio ...':app:clean'. > Unable to delete directory: XX\build\outputs\apk不能删除文件问题
- mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法