怎么删除注册表项 的同时也删除子项及键值

asdfgqwert12 2012-06-30 10:31:55
头文件啦 lib啦都标清楚,举个清除简单的事例昂
...全文
325 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2012-06-30
  • 打赏
  • 举报
回复
RegDeleteTree
也可以遍历,一个的删除
gfm688 2012-06-30
  • 打赏
  • 举报
回复
用SHDeleteKey最简单

#include "shlwapi.h"
#pragma comment(lib, "shlwapi.lib")

SHDeleteKey(HKEY_CURRENT_USER, TEXT("SuKey"));
asdfgqwert12 2012-06-30
  • 打赏
  • 举报
回复
什么打开注册表 安全关闭注册表 请大侠也捎带着写一写
asdfgqwert12 2012-06-30
  • 打赏
  • 举报
回复
什么打开注册表,安全关闭注册表 请大侠也捎带写上哈
dvlinker 2012-06-30
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

vs2008 msdn给出的实例代码,以前用过,所以帮你找了一下。在vs2008 msdn中搜索到的RegCloseKey函数页面中,有这样一个链接:Deleting a Key with Subkeys.,点进去就看到了!
[/Quote]注意这个链接不是网页链接,是msdn中的链接!
dvlinker 2012-06-30
  • 打赏
  • 举报
回复
vs2008 msdn给出的实例代码,以前用过,所以帮你找了一下。在vs2008 msdn中搜索到的RegCloseKey函数页面中,有这样一个链接:Deleting a Key with Subkeys.,点进去就看到了!
dvlinker 2012-06-30
  • 打赏
  • 举报
回复

#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
//*************************************************************
//
// RegDelnodeRecurse()
//
// Purpose: Deletes a registry key and all it's subkeys / values.
//
// Parameters: hKeyRoot - Root key
// lpSubKey - SubKey to delete
//
// Return: TRUE if successful.
// FALSE if an error occurs.
//
//*************************************************************

BOOL RegDelnodeRecurse (HKEY hKeyRoot, LPTSTR lpSubKey)
{
LPTSTR lpEnd;
LONG lResult;
DWORD dwSize;
TCHAR szName[MAX_PATH];
HKEY hKey;
FILETIME ftWrite;

// First, see if we can delete the key without having
// to recurse.

lResult = RegDeleteKey(hKeyRoot, lpSubKey);

if (lResult == ERROR_SUCCESS)
return TRUE;

lResult = RegOpenKeyEx (hKeyRoot, lpSubKey, 0, KEY_READ, &hKey);

if (lResult != ERROR_SUCCESS)
{
if (lResult == ERROR_FILE_NOT_FOUND) {
printf("Key not found.\n");
return TRUE;
}
else {
printf("Error opening key.\n");
return FALSE;
}
}

// Check for an ending slash and add one if it is missing.

lpEnd = lpSubKey + lstrlen(lpSubKey);

if (*(lpEnd - 1) != TEXT('\\'))
{
*lpEnd = TEXT('\\');
lpEnd++;
*lpEnd = TEXT('\0');
}

// Enumerate the keys

dwSize = MAX_PATH;
lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
NULL, NULL, &ftWrite);

if (lResult == ERROR_SUCCESS)
{
do {

StringCchCopy (lpEnd, MAX_PATH*2, szName);

if (!RegDelnodeRecurse(hKeyRoot, lpSubKey)) {
break;
}

dwSize = MAX_PATH;

lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
NULL, NULL, &ftWrite);

} while (lResult == ERROR_SUCCESS);
}

lpEnd--;
*lpEnd = TEXT('\0');

RegCloseKey (hKey);

// Try again to delete the key.

lResult = RegDeleteKey(hKeyRoot, lpSubKey);

if (lResult == ERROR_SUCCESS)
return TRUE;

return FALSE;
}

//*************************************************************
//
// RegDelnode()
//
// Purpose: Deletes a registry key and all it's subkeys / values.
//
// Parameters: hKeyRoot - Root key
// lpSubKey - SubKey to delete
//
// Return: TRUE if successful.
// FALSE if an error occurs.
//
//*************************************************************

BOOL RegDelnode (HKEY hKeyRoot, LPTSTR lpSubKey)
{
TCHAR szDelKey[2 * MAX_PATH];

StringCchCopy (szDelKey, MAX_PATH*2, lpSubKey);
return RegDelnodeRecurse(hKeyRoot, szDelKey);

}

void main()
{
BOOL bSuccess;

bSuccess = RegDelnode(HKEY_CURRENT_USER,
TEXT("Software\\TestDir"));

if(bSuccess)
printf("Success!\n");
else printf("Failure.\n");
}

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧