删除注册表项

lengfengxiaodao 2009-10-15 01:53:42
不是删除值
比如HKEY_CURRENT_USER\Software\Valve\TEST
我想把VALUE全部下面的所有东西全部删除包括TEST
...全文
176 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
windows_star 2009-10-20
  • 打赏
  • 举报
回复
上面是递归删除的代码。
windows_star 2009-10-20
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////////////////////
// DeleRegTree.cpp : Defines the entry point for the console application.
// Author:windowsstar
////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
//bool DeleteTree;

DWORD DeleteTree(HKEY RootKey, const char *pSubKey)
{
HKEY hKey;
DWORD nRet;
DWORD NameCnt,NameMaxLen;
DWORD KeyCnt,KeyMaxLen,MaxDateLen;
static char sFormat[256] = "";
strcat(sFormat, "----");

static int dwDeep = -1;
dwDeep++;

nRet=RegOpenKeyEx(RootKey,pSubKey,0,KEY_ALL_ACCESS,&hKey);
if(nRet!=ERROR_SUCCESS)
{
cout<<"can't open the regedit";
return 0;
}

nRet = RegQueryInfoKey(hKey,NULL,NULL,NULL,&KeyCnt,&KeyMaxLen,NULL,&NameCnt,
&NameMaxLen,&MaxDateLen,NULL,NULL);
if(nRet == ERROR_SUCCESS)
{
for(int dwIndex = KeyCnt - 1; dwIndex >= 0; dwIndex--) //枚举键值
{
char sKeyName[256] = "";
RegEnumKey(hKey, dwIndex, sKeyName, sizeof(sKeyName));

HKEY hKeySub;
DWORD KeyCntSub;
char pSubKeyTemp[256] = "";
strcpy(pSubKeyTemp, pSubKey);
strcat(pSubKeyTemp, "\\");
strcat(pSubKeyTemp, sKeyName);

nRet = RegOpenKeyEx(RootKey,pSubKeyTemp,0,KEY_ALL_ACCESS,&hKeySub);
if(nRet == ERROR_SUCCESS)
{
nRet = RegQueryInfoKey(hKeySub,NULL,NULL,NULL,&KeyCntSub,&KeyMaxLen,NULL,&NameCnt,
&NameMaxLen,&MaxDateLen,NULL,NULL);
if(nRet == ERROR_SUCCESS)
{
if (KeyCntSub != 0)
{
DeleteTree(RootKey, pSubKeyTemp);
}
RegCloseKey(hKeySub);
}
}

// cout << sFormat << sKeyName << endl;

RegDeleteKey(RootKey ,pSubKeyTemp);
}

RegCloseKey(hKey);
}

// sFormat[strlen(sFormat) - 4] = 0;

if (dwDeep == 0)
{
RegDeleteKey(RootKey ,pSubKey);
}

return 0;

}

int main(int argc, char* argv[])
{
//需要删除的子键
DeleteTree(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\TimeStop");
system("pause");
return 0;
}
muzizongheng 2009-10-15
  • 打赏
  • 举报
回复
结贴

jf.
lengfengxiaodao 2009-10-15
  • 打赏
  • 举报
回复
搞定了
marrco2005 2009-10-15
  • 打赏
  • 举报
回复
::SHDeleteKey( HKEY_CURRENT_USER, "HKEY_CURRENT_USER\\Software\\Valve" );
用这个试一下
feilinhe 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yinshisike 的回复:]
枚举.+删除.
[/Quote]
这有代码
http://blog.csdn.net/sding/archive/2008/12/14/3514562.aspx
MoXiaoRab 2009-10-15
  • 打赏
  • 举报
回复
你得先把Test下面的递归删除掉,最后把Test干掉
MoXiaoRab 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lengfengxiaodao 的回复:]
哪有这么麻烦
应该有个API或者其他什么操作一步就可以删除的
[/Quote]
LZ:这个可以有
Tr0j4n:这个真没有
lengfengxiaodao 2009-10-15
  • 打赏
  • 举报
回复
哪有这么麻烦
应该有个API或者其他什么操作一步就可以删除的
yinshisike 2009-10-15
  • 打赏
  • 举报
回复
枚举.+删除.

16,470

社区成员

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

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

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