RegOpenKeyEx返回错误代码87,也称为INVALID_PARAMETER [英] RegOpenKeyEx Returning Error Code 87 aka INVALID_PARAMETER
本文介绍了RegOpenKeyEx返回错误代码87,也称为INVALID_PARAMETER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我编写了一个代码,以从HKLM和HKCR递归删除注册表项.在删除HKLM密钥时没有问题,但是HKCR密钥退出并显示错误代码87,即INVALID_PARAMETER.
知道发生了什么吗?
我的代码段::
hKey =预定义的根密钥,lpszSub =要删除的子密钥
在以下操作系统上运行良好:Vista和Win7,但在XP x86上引发错误
Hi All,
I have written a code to recursively delete the registry keys from HKLM and HKCR. While deleting the HKLM keys pose no problem but HKCR keys exit with the error code 87 i.e., INVALID_PARAMETER.
Any idea on what''s going on?
My Code Snippet::
hKey = Predefined Root Key, lpszSub = SubKey To be Deleted
Works fine on: Vista and Win7 but throws Error on XP x86
static BOOL RcrsvRegDel( HKEY hKey, LPTSTR lpszSub )
{
BOOL bRet = TRUE ;
LONG lRet ;
DWORD dwSize = MAX_PATH ;
TCHAR szName[MAX_PATH] ;
TCHAR szFullKey[MAX_PATH * 2] ;
HKEY hKeySub = NULL ;
HRESULT hr = NULL ;
do{
lRet = RegOpenKeyEx( hKey, lpszSub, 0, KEY_ALL_ACCESS |KEY_WOW64_32KEY , &hKeySub ) ;
printf("RegOpenKey:: %S :: lRet = %ld\n", lpszSub, lRet) ;
if( lRet != ERROR_SUCCESS )
{
if( lRet == ERROR_FILE_NOT_FOUND )
{
bRet = FALSE ;
break ;
}
else
{
bRet = FALSE ;
break ;
}
}
while( ERROR_NO_MORE_ITEMS != (lRet = RegEnumKeyEx(hKeySub, 0, szName, &dwSize, NULL, NULL, NULL, NULL)) )
{
hr = StringCchPrintf( szFullKey, MAX_PATH*2, TEXT("%s\\\\%s\0"), lpszSub, szName ) ;
if( hr != S_OK )
{
bRet = FALSE ;
break ;
}
szName[0] = '\0' ;
dwSize = MAX_PATH ;
bRet = K7RT_RcrsvRegDel( hKey, szFullKey ) ;
if( bRet == FALSE )
break ;
}
if( hKeySub != NULL )
{
RegCloseKey(hKeySub) ;
hKeySub = NULL ;
}
lRet = RegDeleteKey( hKey, lpszSub ) ;
printf("RegDelKey:: %S :: lRet = %ld\n", lpszSub, lRet) ;
if( lRet == ERROR_SUCCESS )
{
bRet = TRUE ;
break ;
}
}while(0) ;
return bRet ;
}
推荐答案
在第一个RegDeleteKey()
之后,如果删除成功,则将关闭句柄.但是您没有清除hKey
变量,该变量随后在以后再次用于关闭密钥而失败:
After the firstRegDeleteKey()
you are closing the handle if deletion was successful. But you did not clear thehKey
variable which is then used later to close the key again which fails:
if( lRet == ERROR_SUCCESS )
{
bRet = TRUE ;
RegCloseKey(hKey) ;
// This line is missing in your code:
hKey = NULL ;
break ;
}
似乎您正在尝试执行此函数为您执行的操作:
RegDeleteTree [
Seems like you are trying to do what this function does for you:
RegDeleteTree[^]
Deletes the subkeys and values of the specified key recursively
Best regards
Espen Harlinn
检查
hKeySub
这篇关于RegOpenKeyEx返回错误代码87,也称为INVALID_PARAMETER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文