Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
3.22/5 (3 votes)
Hi all,
I Searched how to delete a whole key from the Registry using c++
anyone here can help me because i didnt find any clear example about this subject.

the key path is like here :
Computer\HKEY_USERS\folder \folder\ folder\{Key name}.

So i want to delete this key by its path.

What I have tried:

i searched in other sites like stackover.. . and in microsoft site i didnt understand how their library works because i didnt see any clear example that explain how this could happen.
Posted
Updated 27-Oct-22 20:45pm
v2

 
Share this answer
 
In the code below you can see how to delete a subkey or the entiry key
HKEY hKey = NULL;
long lReturn = RegOpenKeyEx( HKEY_USERS.
                             _T("folder \folder\ folder\{Key name}"),
                             0L,
                             KEY_SET_VALUE,
                             &hKey );
if (lReturn == ERROR_SUCCESS)
{
    lReturn = RegDeleteValue(hKey, _T("value1"));
    lReturn = RegDeleteValue(hKey, _T("value2"));
    lReturn = RegCloseKey(hKey);
}


Now to delete the entire key:

lReturn = RegDeleteKey(HKEY_CURRENT_USER, _T("folder \folder\ folder\{Key name}"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900