#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winreg.h>
#include <tchar.h>
#include <shlwapi.h>
#include <iostream.h>
char * NumTOSymbol(int SymbolNum)
{
char *symbol=new char[SymbolNum+1];
memset(symbol,'/0',SymbolNum+1);
for(int i=0;i<SymbolNum;i++)
strcat(symbol,"-");
return symbol;
}
int EnumRegKey(IN HKEY hRootKey,IN char * strKeyPath)
{
HKEY regOldHKey;
char *strPath=new char[strlen(strKeyPath)+1];
strcpy(strPath,strKeyPath);
DWORD dwIndex=0; //子键项值的序号
DWORD index=0; // 子键的序号
char *subKeyName=new char[MAX_PATH]; //用来保存子键的值
DWORD dwLen=MAX_PATH; //子键的长度
char strClass[MAX_PATH]; //class name
DWORD dwClassLen=MAX_PATH; //len of class name
FILETIME ftLastTime; // the struct
CHAR* tcKeyName = new CHAR[MAX_PATH]; //子键项的名字
DWORD dwKeyNameLen = MAX_PATH; //
LPBYTE newByte = new BYTE[MAX_PATH]; //子键项名字的长度
DWORD nType; //子键项的数值类型
DWORD lpSize=MAX_PATH;
LPBYTE pbbinKeyData=NULL;
static int iSymbolNum=0; //标识子键在目录中的层次
if(RegOpenKeyEx(hRootKey,strPath,NULL,KEY_READ,®OldHKey)==ERROR_SUCCESS)
{
iSymbolNum++;
while(true) //先列举该子键下的所有键值项
{
if(RegEnumValue(regOldHKey,dwIndex,(LPTSTR)tcKeyName,&dwKeyNameLen,NULL,&nType,newByte,&lpSize)!=ERROR_SUCCESS)
break;
/*cout<<"Key:"<<(LPCTSTR)tcKeyName;
cout<<"/t";
cout<<"Value:"<<(LPCTSTR)newByte<<"length : "<<lpSize<<endl;*/
printf("%s Key : %-20s Value : %-20s Length : %d/n",NumTOSymbol(iSymbolNum),(LPTSTR)tcKeyName,newByte,lpSize);
dwIndex++;
dwKeyNameLen=MAX_PATH;
lpSize=MAX_PATH;
} //while
while(true)
{
if(RegEnumKeyEx(regOldHKey,index,(LPSTR)subKeyName,&dwLen,NULL,(LPSTR)strClass,
&dwClassLen,&ftLastTime)!=ERROR_SUCCESS)
{
//cout<<"枚举结束,退出循环!/n";
break;
}
printf("%s 子键名 : %-20s 长度 : %d/n",NumTOSymbol(iSymbolNum),(LPSTR)subKeyName,dwLen);
//cout<<"最后一次修改时间 :/t"<<ftLastTime.dwHighDateTime<<endl;
strPath=new char[strlen(strKeyPath)+strlen(subKeyName)+1+1];
strcpy(strPath,strKeyPath);
strcat(strPath,"//");
strcat(strPath,subKeyName);
//cout<<"strPath = "<<strPath<<endl;
EnumRegKey(hRootKey,strPath);
iSymbolNum--; //层次减少
index++;
dwLen=MAX_PATH;
dwClassLen=MAX_PATH;
} //while
RegCloseKey(regOldHKey);
}
else
{
cout<<"打开注册表失败!/n";
return 0;
}
return 1;
}
void main() { EnumRegKey(HKEY_LOCAL_MACHINE,"Software//Google"); }