递归调用遍历注册表
Posted by gleon on 2006/10/22
/********************************************************************
created: 2006/10/22
created: 22:10:2006 1:44
file ext: cpp
author: Gleon
E-Mail: WinAsk@Gmail.CoM
purpose: 递归调用遍历注册表
*********************************************************************/
#include "stdafx.h"
#include "windows.h"
#define MAX_KEY_LENGTH 1024
int ReadKeyValue(HKEY hKey)
{
DWORD dwIndex,Type,ReSizeName,ReSizeValue;
TCHAR Name[1024];
TCHAR Value[1024];
int ret=0;
dwIndex=0;
ReSizeName=sizeof(Name);
ReSizeValue=sizeof(Value);
ZeroMemory(Name,sizeof(Name));
ZeroMemory(Value,sizeof(Value));
while(RegEnumValue(hKey,dwIndex,(LPTSTR)Name,&ReSizeName,NULL,&Type,(LPBYTE)Value,&ReSizeValue)!=ERROR_NO_MORE_ITEMS)
{
dwIndex++;
if(ReSizeName==0)
continue;
printf("---------------------------------------\n");
printf("Name :%s\n",Name);
printf("Value :%s\n",Value);
ReSizeName=sizeof(Name);
ReSizeValue=sizeof(Value);
ret=1;
}
return ret;
}
void RegSearch(HKEY hKey, TCHAR rootKey[],char *path)
{
DWORD numSubKey=0; //存放子键的项数
DWORD dwIndex; //计数
DWORD ReSizeSubKey;
TCHAR subKey[MAX_KEY_LENGTH]; //子键名
dwIndex=0;
ReSizeSubKey=MAX_KEY_LENGTH;
if(RegOpenKeyEx(hKey,
rootKey,
0,
KEY_READ,
&hKey)!=ERROR_SUCCESS)
{
return ;
}
printf("SubKey:%s\n",path);
ReadKeyValue(hKey); //读取当前Key 下面的所有值
while(RegEnumKeyEx( hKey,dwIndex,subKey,&ReSizeSubKey,NULL,NULL,NULL,NULL)!=ERROR_NO_MORE_ITEMS)
{ dwIndex++;
strcat(path,subKey);
strcat(path,"\\");
printf("%s\n",path);
RegSearch (hKey,subKey,path); //递归
}
RegCloseKey(hKey);
}
int main(int argc, char* argv[])
{
char path[1024*10];
strcpy(path,"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\helpsvc\\");
RegSearch(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\helpsvc",path);
return 0;
}
随机日志
0 评论.