RegDeleteKey

3.1

  #include <shellapi.h>    

  LONG RegDeleteKey(hkey, lpszSubKey)    
  HKEY hkey; /* handle of an open key */
  LPCSTR lpszSubKey; /* address of string for subkey to delete */

The RegDeleteKey function deletes the specified key. When a key is deleted, its value and all of its subkeys are deleted.

Parameters

hkey

Identifies an open key (which can be HKEY_CLASSES_ROOT). The key deleted by the RegDeleteKey function is a subkey of this key.

lpszSubKey

Points to a null-terminated string specifying the subkey to delete. This value should not be NULL.

Return Value

The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.

If the error value is ERROR_ACCESS_DENIED, either the application does not have delete privileges for the specified key or another application has opened the specified key.

Example

The following example uses the RegQueryValue function to retrieve the name of an object handler and then calls the RegDeleteKey function to delete the key if its value is nwappobj.dll:

char szBuff[80];
LONG cb;
HKEY hkStdFileEditing;

if (RegOpenKey(HKEY_CLASSES_ROOT,
        "NewAppDocument\\protocol\\StdFileEditing",
        &hkStdFileEditing) == ERROR_SUCCESS) {

    cb = sizeof(szBuff);
    


        


if (RegQueryValue(hkStdFileEditing,
            "handler",
            szBuff,
            &cb) == ERROR_SUCCESS
            && lstrcmpi("nwappobj.dll", szBuff) == 0)
        RegDeleteKey(hkStdFileEditing, "handler");
    RegCloseKey(hkStdFileEditing);
}

See Also

RegCloseKey