Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Delete HKEY on NT only
- DWORD RegDeleteKeyNT(
- HKEY hStartKey,
- LPCTSTR pKeyName
- ) {
- DWORD dwRtn, dwSubKeyLength;
- //LPTSTR pSubKey = NULL;
- TCHAR szSubKey[500];//MAX_KEY_LENGTH]; // (256) this should be dynamic.
- HKEY hKey;
- // do not allow NULL or empty key name
- if (pKeyName && lstrlen(pKeyName)) {
- if ((dwRtn=RegOpenKeyEx(hStartKey,pKeyName,
- 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey )) == ERROR_SUCCESS) {
- //int index = 0;
- while (dwRtn == ERROR_SUCCESS ) {
- dwSubKeyLength = 500;//MAX_KEY_LENGTH;
- dwRtn=RegEnumKeyEx(
- hKey,
- 0, // always index zero
- szSubKey,
- &dwSubKeyLength,
- NULL,
- NULL,
- NULL,
- NULL
- );
- if (dwRtn == ERROR_NO_MORE_ITEMS) {
- dwRtn = RegDeleteKey(hStartKey, pKeyName);
- break;
- }
- else if (dwRtn == ERROR_SUCCESS)
- dwRtn=RegDeleteKeyNT(hKey, szSubKey);
- }
- RegCloseKey(hKey);
- }
- }
- else
- dwRtn = ERROR_BADKEY;
- return dwRtn;
- }
Advertisement
Add Comment
Please, Sign In to add comment