Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Registry Settings

Status
Not open for further replies.

TheMillionDollarMan

Programmer
Jun 10, 2002
132
US
How do I do this in Code?
I know the command lines to add etc but this one is tough to find.

Thanks

Win2k, VC++ 6.
 
From the MSDN:
------------------------------------------------------------

Platform SDK: Windows System Information

RegDeleteKey
The RegDeleteKey function deletes a subkey, including all of its values.

LONG RegDeleteKey(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey // subkey name
);Parameters
hKey
[in] Handle to an open key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows 95/98/Me: HKEY_DYN_DATA

The key must have been opened with the DELETE access right. For more information, see Registry Key Security and Access Rights.

lpSubKey
[in] Pointer to a null-terminated string specifying the name of the key to be deleted. It must be a subkey of the key identified by hKey. This parameter cannot be NULL.
Windows NT/2000/XP: The specified key must not have subkeys.

For more information, see Registry Element Size Limits.

Return Values
If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks
A deleted key is not removed until the last handle to it has been closed.

Windows NT/2000/XP: The subkey to be deleted must not have subkeys. To delete a key and all its subkeys, you need to recursively enumerate the subkeys and delete them individually. To recursively delete keys, use the SHDeleteKey function.

Windows 95/98/Me: The function also deletes all subkeys and values. To delete a key only if the key has no subkeys or values, use the SHDeleteEmptyKey function.

Windows 95/98/Me: RegDeleteKeyW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
 
Or, if you're looking for this, also from the MSDN:
---------------------------------------------------------
Code:
Platform SDK: Windows System Information 

RegDeleteValue
The RegDeleteValue function removes a named value from the specified registry key. 

LONG RegDeleteValue(
  HKEY hKey,            // handle to key
  LPCTSTR lpValueName   // value name
);Parameters
hKey 
[in] Handle to an open key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys: 
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows 95/98/Me: HKEY_DYN_DATA 

The key must have been opened with the KEY_SET_VALUE access right. For more information, see Registry Key Security and Access Rights. 

lpValueName 
[in] Pointer to a null-terminated string that names the value to remove. If this parameter is NULL or an empty string, the value set by the RegSetValue function is removed. 
For more information, see Registry Element Size Limits. 

Return Values
If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks
Windows 95/98/Me: RegDeleteValueW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Requirements 
  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Winreg.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top