tags:

views:

55

answers:

2

Is there an API that will delete all the values under a specific registry key?

for example, I have the following key

HKEY_CURRENT_USER\Software\MyCompany\Program\Myconfig

under it I have

(Default)
SomeVal
SomeOtherVal
YetSomeOtherVat
...

There might be 10, 20, 100 values there. It depends what you set on the application. Is there a way in C to delete them all without having to iterate one by one and delete them?

Thanks, code is appreciated.

A: 

This ought to do it:

if (RegDeleteTree("HKEY_CURRENT_USER", "Software\MyCompany\Program\Myconfig") == ERROR_SUCCESS)
{
    . . .
}

This function deletes a specified registry key and all its subkeys. However, there is an issue with Windows 7 deleting keys on a Windows XP machine using this. See MSDN for details.

Amardeep
+1  A: 

The SHDeleteKey function from Shlwapi.lib does what you want.

When you only need this on Vista and later OS versions, you can use RegDeleteTree

Christopher