RegistryHelper::splitKey
wstring RegistryHelper::splitKey(const wstring& key, HKEY* rootKey)
{
size_t pos = key.find(L'\\');
if (pos == wstring::npos)
throw RegistryException(L"Key " + key + L" has invalid format");
wstring rootPart = key.substr(0, pos);
wstring pathPart = key.substr(pos + 1);
wstring p = StringHelper::toUpperCase(rootPart);
if (p == L"HKEY_CLASSES_ROOT")
*rootKey = HKEY_CLASSES_ROOT;
else if (p == L"HKEY_CURRENT_CONFIG")
*rootKey = HKEY_CURRENT_CONFIG;
else if (p == L"HKEY_CURRENT_USER")
*rootKey = HKEY_CURRENT_USER;
else if (p == L"HKEY_LOCAL_MACHINE")
*rootKey = HKEY_LOCAL_MACHINE;
else if (p == L"HKEY_USERS")
*rootKey = HKEY_USERS;
else
throw RegistryException(L"Unknown root key " + rootPart);
return pathPart;
}
随手分享,手有余香