- void DeleteRegKey(HKEY rootKey, LPCWSTR subKey)
- {
- HKEY hKey;
- if (RegOpenKeyExW(rootKey, subKey, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
- {
- while (true)
- {
- // 注册表项名称最长为251个有效字符
- WCHAR subKeyName[251] = L"";
- if (RegEnumKeyW(hKey, 0, subKeyName, 251) != ERROR_SUCCESS)
- break;
- // 这里的2是路径分隔符"\\"和结束符的占位
- size_t fullPathLen = wcslen(subKey) + 2 + wcslen(subKeyName);
- WCHAR *fullPath = new WCHAR[fullPathLen];
- wcscpy(fullPath, subKey);
- wcscat(fullPath, L"\\");
- wcscat(fullPath, subKeyName);
- DeleteRegKey(rootKey, fullPath);
- delete[] fullPath;
- }
- RegDeleteKeyW(rootKey, subKey);
- RegCloseKey(hKey);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/130520149555.html
来源: http://www.codesnippet.cn/detail/130520149555.html