Ejemplo n.º 1
0
void WinRegistryKey::deleteKey() {
	Keys keys;
	subKeys(keys);
	close();
	for (Keys::iterator it = keys.begin(); it != keys.end(); ++it) {
		string subKey(_subKey);
		subKey += "\\";
		subKey += *it;
		WinRegistryKey subRegKey(_hRootKey, subKey);
		subRegKey.deleteKey();
	}

	// NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later.
	// We cannot call it directly as this would prevent the code running on Windows XP 32-bit.
	// Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for
	// its existence in ADVAPI32.DLL and call it indirectly.
	typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved);
	if (_extraSam != 0) {
		AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL"));
		if (advAPI32.handle()) {
			RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA"));
			if (pRegDeleteKeyExA) {
				(*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0);
				return;
			}
		}
	}
	RegDeleteKey(_hRootKey, _subKey.c_str());
}
Ejemplo n.º 2
0
void WinRegistryKey::deleteKey()
{
	Keys keys;
	subKeys(keys);
	close();
	for (Keys::iterator it = keys.begin(); it != keys.end(); ++it)
	{
		std::string subKey(_subKey);
		subKey += "\\";
		subKey += *it;
		WinRegistryKey subRegKey(_hRootKey, subKey);
		subRegKey.deleteKey();
	}

	// NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later.
	// We cannot call it directly as this would prevent the code running on Windows XP 32-bit.
	// Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for
	// its existence in ADVAPI32.DLL and call it indirectly.
#if defined(POCO_WIN32_UTF8)
	std::wstring usubKey;
	Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
	
	typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
	if (_extraSam != 0)
	{
		AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL"));
		if (advAPI32.handle())
		{
			RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW"));
			if (pRegDeleteKeyExW)
			{
				if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
					throw NotFoundException(key());
				return;
			}
		}
	}
	if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key());
#else
	typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved);
	if (_extraSam != 0)
	{
		AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL"));
		if (advAPI32.handle())
		{
			RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA"));
			if (pRegDeleteKeyExA)
			{
				if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
					throw NotFoundException(key());
				return;
			}
		}
	}
	if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key());
#endif
}
Ejemplo n.º 3
0
// for WinNT we need to delete recursively ourselves
HRESULT RegistryClass::DeleteKey (LPCTSTR pszKey, const BOOL fRecursive)
{
	if ((NULL == m_hKey) || IsEmptyStr(pszKey))
		return ERROR_BAD_ARGUMENTS;

	if (fRecursive)
	{
		RegistryClass	rsk;
		HRESULT			hr=rsk.SetBasedLocation(*this, pszKey, KEY_ALL_ACCESS, FALSE);
		if (hr != ERROR_SUCCESS)
			return hr;

		static const UINT32	AVG_SUBKEYS_NUM=16;
		CVSDCollection		subKeys(AVG_SUBKEYS_NUM,AVG_SUBKEYS_NUM);
		RegistryClassEnum	rce(&rsk);

		static const UINT32	MAX_KEYNAME_LEN=64;
		TCHAR	szKeyName[MAX_KEYNAME_LEN+2]=_T("");
		DWORD	dwKNLen=(MAX_KEYNAME_LEN+1);

		// first, "collect" all keys since deletion changes enumeration
		for (hr=rce.GetFirstKey(szKeyName, &dwKNLen);
			 (ERROR_SUCCESS == hr);
			 dwKNLen=(MAX_KEYNAME_LEN+1), hr=rce.GetNextKey(szKeyName, &dwKNLen))
		{
			UINT32	ulKNLen=_tcslen(szKeyName);
			if ((hr=subKeys.AddItem(szKeyName, ((ulKNLen+1) * sizeof(TCHAR)))) != ERROR_SUCCESS)
				return hr;
		}

		// now delete recursively
		CVSDCollEnum	ske(subKeys);
		LPVOID			pItem=NULL;
		for (hr=ske.GetFirstItem(pItem); ERROR_SUCCESS == hr; hr=ske.GetNextItem(pItem))
			if ((hr=rsk.DeleteKey((LPCTSTR) pItem, TRUE)) != ERROR_SUCCESS)
				return hr;
	}

	return RegDeleteKey((HKEY) m_hKey, (LPCTSTR) pszKey);
}
Ejemplo n.º 4
0
void WinRegistryKey::deleteKey()
{
	Keys keys;
	subKeys(keys);
	close();
	for (Keys::iterator it = keys.begin(); it != keys.end(); ++it)
	{
		std::string subKey(_subKey);
		subKey += "\\";
		subKey += *it;
		WinRegistryKey subRegKey(_hRootKey, subKey);
		subRegKey.deleteKey();
	}
#if defined(POCO_WIN32_UTF8)
	std::wstring usubKey;
	Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
	if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key());
#else
	if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key());
#endif
}
Ejemplo n.º 5
0
QStringList Config::LauncherSettings::getContentLists()
{
    return subKeys(QString(sContentListsSectionPrefix));
}