Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
912 B

#include <windows.h>
LONG RegDeleteKeyRecursively(HKEY hkRootKey, PCSTR pcszSubKey)
{
LONG lErr;
if ((lErr = RegDeleteKey(hkRootKey, pcszSubKey)) != ERROR_SUCCESS)
{
HKEY hkSubKey;
// delete the key recursively
if ((lErr = RegOpenKeyEx(hkRootKey, pcszSubKey, 0, KEY_READ | KEY_WRITE, &hkSubKey)) == ERROR_SUCCESS)
{
CHAR szSubKeyName[MAX_PATH + 1];
DWORD dwIndex;
if ((lErr = RegQueryInfoKey(hkSubKey, NULL, NULL, NULL, &dwIndex, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
while (RegEnumKey(hkSubKey, --dwIndex, szSubKeyName, sizeof(szSubKeyName)) == ERROR_SUCCESS)
RegDeleteKeyRecursively(hkSubKey, szSubKeyName);
RegCloseKey(hkSubKey);
lErr = RegDeleteKey(hkRootKey, pcszSubKey);
}
}
return lErr;
}