Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:55:11+00:00 2026-06-12T10:55:11+00:00

I am implementing a recursive registry delete using RegOpenKeyEx, RegDeleteKey and RegEnumKey. Problem:: Though

  • 0

I am implementing a recursive registry delete using RegOpenKeyEx, RegDeleteKey and RegEnumKey.

Problem:: Though the code works perfectly fine for Vista x86/x64 and Win 7 x86/x64 but fails on XP for some keys in HKCR

Problem Area:: HKCR\Installer\Products\SomeKey

Error Code:: 87 (INVALID_PARAMETER)

Weird Behaviour:: Deletes the key the moment I open the key using REGEDIT.

Code::

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_ENUMERATE_SUB_KEYS | DELETE, &hKeySub ) ;
    printf("RegOpenKey:: %S :: lRet = %ld\n", lpszSub, lRet) ;
    if( lRet != ERROR_SUCCESS )
    {
        if( lRet == ERROR_FILE_NOT_FOUND )
        {
            bRet = TRUE ;
            break ;
        }
        else
        {
            bRet = FALSE ;
            break ;
        }
    }

    while( ERROR_NO_MORE_ITEMS != (lRet = RegEnumKeyEx(hKeySub, 0, szName, &dwSize, NULL, NULL, NULL, NULL)) )
    {
        bRet = RcrsvRegDel( hKeySub, szName) ;
        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 ;
}

Any idea whats goin on?

UPDATE::

I have also tried the samDesired Parameter with following flags

-KEY_READ

-KEY_READ | KEY_WRITE

-KEY_ENUMERATE_SUB_KEYS

-KEY_ENUMERATE_SUB_KEYS | DELETE

Neither of the above flag works 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:55:13+00:00Added an answer on June 12, 2026 at 10:55 am

    You can do like this. Take the flag as input parameter and pass one flag for the RegOpenKeyEx and again a set of flags when calling the recursive function. I have tried your code and it is working perfectly now, though it is not sure as to what was it that was causing the problem.

    static BOOL RcrsvRegDel( HKEY hKey, LPTSTR lpszSub, DWORD dwOpenFlags )
    {
        BOOL    bRet = TRUE ;
        LONG    lRet ;
        DWORD   dwSize = MAX_PATH ;
        TCHAR   szName[MAX_PATH] ;
        HKEY    hKeySub = NULL ;
        HRESULT hr = NULL ;
        HANDLE  hProcess = NULL ;
        HANDLE  hToken = NULL ;
    
        do{
            bRet = SetPrivilege( SE_BACKUP_NAME, TRUE ) ;
            if( bRet == FALSE )
            {
                bRet = FALSE ;
                break ;
            }
    
            lRet = RegOpenKeyEx( hKey, lpszSub, 0, dwOpenFlags, &hKeySub ) ;
            if( lRet != ERROR_SUCCESS )
            {
                bRet = FALSE ;
                break ;
            }
    
            while( ERROR_NO_MORE_ITEMS != (lRet = RegEnumKeyEx(hKeySub, 0, szName, &dwSize, NULL, 
                NULL, NULL, NULL)) )
                if( !RcrsvRegDel(hKeySub, szName, dwOpenFlags) ) 
                {
                    bRet = FALSE ;
                    break ;
                }
    
            lRet = RegDeleteKey( hKey, lpszSub ) ;
            printf("RegDelKey:: %S :: lRet = %ld\n", lpszSub, lRet) ;
            if( lRet != ERROR_SUCCESS )
            {
                bRet = FALSE ;
                break ;
            }
    
            if( hKeySub != NULL )
            {
                RegCloseKey(hKeySub) ;
                hKeySub = NULL ;
            }
        }while(0) ;
        return bRet ;
    }
    
    static BOOL SetPrivilege( LPCTSTR lpszPrivilege, BOOL bEnablePrivilege ) 
    {
        LUID    luid ;
        BOOL    bRet = TRUE ;
        HANDLE  hToken = NULL ;
        HANDLE  hProcess = NULL ;
        TOKEN_PRIVILEGES tp ;
    
        do{
            hProcess = GetCurrentProcess() ;
            if( 0 == OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken) )
            {
                bRet = FALSE ;
                break ;
            }
    
            if( !LookupPrivilegeValue(NULL, lpszPrivilege, &luid) )
            {
                bRet = FALSE ;
                break ;
            }
    
            tp.PrivilegeCount = 1 ;
            tp.Privileges[0].Luid = luid ;
    
            if( bEnablePrivilege )
                tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
            else
                tp.Privileges[0].Attributes = 0 ;
    
            if( !AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, 
                (PDWORD)NULL) )
            {
                bRet = FALSE ;
                break ;
            }
    
            if( ERROR_NOT_ALL_ASSIGNED == GetLastError() )
            {
                bRet = FALSE ;
                break ;
            }
        }while(0) ;
        if( hToken != NULL ) CloseHandle( hToken ) ;
        return bRet ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I am having trouble implementing a recursive image lazy load in all relevant
implementing publishActivity in PHP using the REST API using this code: $activity = array(
I've recently been implementing a recursive directory search implementation and I'm using a Stack
I was implementing a chess bot in c++ using recursive algorithms and the program
when implementing a recursive function during development, i will use a counter and exit
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
When implementing a hash table using a good hash function (one where the probability
I am implementing a fairly simple calendar on a website using PHP and MySQL.
I am implementing a recursive algorithm: def induct(arg): if doStuff(arg) == 0: return #
I´m having some trouble implementing a dynamic tree structure using the primefaces tree implementation.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.