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 ;
}