BOOL CRKey::DeleteSubKeys(HKEY hRoot, LPCTSTR pKey) {_STTEX(); HKEY hKey; char szKey[ CWF_STRSIZE ]; DWORD dwSize = CWF_STRSIZE - 1; // Open The Key if( RegOpenKeyEx( hRoot, pKey, 0, KEY_ALL_ACCESS, &hKey ) != ERROR_SUCCESS ) return FALSE; // For each sub key while ( RegEnumKeyEx( hKey, 0, szKey, &dwSize, NULL, NULL, NULL, NULL ) == ERROR_SUCCESS ) { // A little recursion DeleteSubKeys( hKey, szKey ); // Attempt to delete the key RegDeleteKey( hKey, szKey ); // Reset size dwSize = CWF_STRSIZE - 1; } // end while // Close the key RegCloseKey( hKey ); return TRUE; }
BOOL CAutoReg::DeleteSubKeys ( HKEY hRoot, LPCTSTR pKey ) {_STTEX(); HKEY hKey; char szKey[ MAX_PATH ]; DWORD dwSize = MAX_PATH - 1; FILETIME ft; ZeroMemory( (LPVOID)&ft, sizeof( FILETIME ) ); // Open The Key if( RegOpenKeyEx( hRoot, pKey, 0, KEY_ALL_ACCESS, &hKey ) != ERROR_SUCCESS ) return FALSE; // For each sub key while ( RegEnumKeyEx( hKey, 0, szKey, &dwSize, NULL, NULL, NULL, &ft ) == ERROR_SUCCESS ) { // A little recursion DeleteSubKeys( hKey, szKey ); // Attempt to delete the key RegDeleteKey( hKey, szKey ); dwSize = MAX_PATH - 1; } // end while // Close the key RegCloseKey( hKey ); return TRUE; }
BOOL CRKey::DeleteKey(HKEY hKey, LPCTSTR pKey, BOOL bSubKeys) {_STTEX(); // Delete sub keys if needed if ( bSubKeys ) DeleteSubKeys( hKey, pKey ); // Attempt to delete the key return ( RegDeleteKey( hKey, pKey ) == ERROR_SUCCESS ); }
BOOL CAutoReg::DeleteSubKeys ( LPCTSTR pName, LPREGENTRY pReg, LPCTSTR pComputer ) {_STTEX(); BOOL bRet = FALSE; HKEY hRoot; char szKey[ MAX_PATH ]; BOOL bRemote = FALSE; DWORD access = 0; // Sanity Check if ( pReg == NULL ) return FALSE; // Generate key name szKey[ 0 ] = 0x0; strcpy( szKey, pReg->szKey ); if ( pName != NULL && pName[ 0 ] != 0x0 ) { if ( szKey[ 0 ] != 0x0 ) strcat( szKey, "\\" ); strcat( szKey, pName ); } // end if // Connect to remote computer if needed if ( pReg->szComputer[ 0 ] != 0x0 ) { if ( RegConnectRegistry( pReg->szComputer, pReg->hKey, &hRoot ) != ERROR_SUCCESS ) return 0; bRemote = TRUE; } else if ( pComputer != NULL && pComputer[ 0 ] != 0x0 ) { if ( RegConnectRegistry( (char*)pComputer, pReg->hKey, &hRoot ) != ERROR_SUCCESS ) return 0; bRemote = TRUE; } // end else if // Must want the local machine else hRoot = pReg->hKey; // Attempt to delete the Sub-keys if( DeleteSubKeys( hRoot, szKey ) == ERROR_SUCCESS ) bRet = TRUE; // Close the remote key if needed if ( bRemote ) RegCloseKey( hRoot ); return bRet; }