示例#1
0
LONG CRegKey2::RecurseDeleteKey(HKEY key, LPCTSTR lpszKey)
{
	HKEY rslt;
	LONG lRes;
	FILETIME time;
	TCHAR szBuffer[256];
	DWORD dwSize = 256;

	lRes = RegOpenKeyEx(key, lpszKey, 0, (KEY_READ | KEY_WRITE), &rslt);

	if (lRes != ERROR_SUCCESS)
		return lRes;

	while (RegEnumKeyEx(rslt, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time) == ERROR_SUCCESS)
	{
		lRes = RecurseDeleteKey(rslt, szBuffer);

		if (lRes != ERROR_SUCCESS)
			return lRes;

		dwSize = 256;
	}

	RegCloseKey(rslt);

	return RegDeleteKey(key, lpszKey);
}
bool CXTPRegistryManager::DeleteKey(LPCTSTR lpszSection, LPCTSTR lpszKey)
{
	CHKey hSectionKey(GetSectionKey(lpszSection));
	if (hSectionKey == NULL)
		return false;

	return (RecurseDeleteKey(hSectionKey, lpszKey) == ERROR_SUCCESS);
}
示例#3
0
void UnregisterServer()
{
    char achIMEKey[ARRAYSIZE(c_szInfoKeyPrefix) + CLSID_STRLEN];

    if (!CLSIDToStringA(c_clsidTextService, achIMEKey + ARRAYSIZE(c_szInfoKeyPrefix) - 1))
        return;
    memcpy(achIMEKey, c_szInfoKeyPrefix, sizeof(c_szInfoKeyPrefix)-sizeof(TCHAR));

    RecurseDeleteKey(HKEY_CLASSES_ROOT, (LPCTSTR)achIMEKey);
}
LONG
RecurseDeleteKey(
    CHKey&  rhkParent,
    LPCTSTR ptszKeyname,
    int     nLevels /* =0 */)
{
    ASSERT(ptszKeyname != NULL);

    //TRACE(_T("%*sRecurseDeleteKey(%s)\n"), 4 * nLevels, _T(""),  ptszKeyname);

    CHKey hk;

    if (! hk.OpenKey(rhkParent, ptszKeyname, KEY_ALL_ACCESS))
        return hk.ReportError();

    FILETIME ftLastWriteTime;
    DWORD    ctcMaxSubkeyLen = 0;      // longest subkey name length  

    if (! hk.QueryInfoKey(NULL, NULL, NULL, &ctcMaxSubkeyLen, NULL,
                          NULL, NULL, NULL, NULL, &ftLastWriteTime))
        return hk.Error();

    DWORD  ctcSubkeyName  = ++ctcMaxSubkeyLen;
    LPTSTR ptszSubkeyName = (LPTSTR) _alloca(ctcSubkeyName * sizeof(TCHAR));

    while (hk.EnumKey(0, ptszSubkeyName, &ctcSubkeyName,
                      NULL, NULL, &ftLastWriteTime))
    {
        LONG l = RecurseDeleteKey(hk, ptszSubkeyName, nLevels + 1);

        if (l != ERROR_SUCCESS)
            return l;

        ctcSubkeyName  = ctcMaxSubkeyLen;
    }

    rhkParent.DeleteKey(ptszKeyname);

    return rhkParent.Error();
}
示例#5
0
//+---------------------------------------------------------------------------
//
// RecurseDeleteKey
//
// RecurseDeleteKey is necessary because on NT RegDeleteKey doesn't work if the
// specified key has subkeys
//----------------------------------------------------------------------------
LONG RecurseDeleteKey(HKEY hParentKey, LPCTSTR lpszKey)
{
    HKEY hKey;
    LONG lRes;
    FILETIME time;
    TCHAR szBuffer[256];
    DWORD dwSize = ARRAYSIZE(szBuffer);

    if (RegOpenKey(hParentKey, lpszKey, &hKey) != ERROR_SUCCESS)
        return ERROR_SUCCESS; // assume it couldn't be opened because it's not there

    lRes = ERROR_SUCCESS;
    while (RegEnumKeyEx(hKey, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time)==ERROR_SUCCESS)
    {
        szBuffer[ARRAYSIZE(szBuffer)-1] = '\0';
        lRes = RecurseDeleteKey(hKey, szBuffer);
        if (lRes != ERROR_SUCCESS)
            break;
        dwSize = ARRAYSIZE(szBuffer);
    }
    RegCloseKey(hKey);

    return lRes == ERROR_SUCCESS ? RegDeleteKey(hParentKey, lpszKey) : lRes;
}
LONG CXTPRegistryManager::RecurseDeleteKey(HKEY hKey, LPCTSTR lpszKey)
{
	CHKey hSubKey;
	LONG lRes = ::RegOpenKeyEx(hKey, lpszKey, 0, KEY_READ | KEY_WRITE, hSubKey);
	if (lRes != ERROR_SUCCESS)
		return lRes;

	FILETIME time;
	DWORD dwSize = 256;
	TCHAR szBuffer[256];

	while (::RegEnumKeyEx(hSubKey, 0, szBuffer, &dwSize, NULL, NULL, NULL,
		&time) == ERROR_SUCCESS)
	{
		lRes = RecurseDeleteKey(hSubKey, szBuffer);
		if (lRes != ERROR_SUCCESS)
			return lRes;

		dwSize = 256;
	}

	m_lResult = ::RegDeleteKey(hKey, lpszKey);
	return m_lResult;
}
示例#7
0
LONG CRegKey2::DeleteKey(HKEY hKeyRoot, LPCTSTR pszPath)
{
	return RecurseDeleteKey(hKeyRoot, pszPath);
}