#include <stdio.h> #include <windows.h> #define SUBKEYS 1 //枚举注册表 void EnumRegKey(){ HKEY hKey=NULL,h=NULL; char str[MAX_PATH]; DWORD num=sizeof(str),index=0,rc; #if SUBKEYS rc=::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE",0,KEY_ALL_ACCESS,&hKey); #else rc=::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",0,KEY_ALL_ACCESS,&hKey); #endif if(rc==ERROR_SUCCESS) { #if SUBKEYS while(RegEnumKeyEx(hKey,index,str,&num,NULL,NULL,NULL,NULL)==0) #else while(RegEnumValue(hKey,index,str,&num,NULL,NULL,NULL,NULL)==0) #endif { printf("%s \n",str); index++; num=MAX_PATH; } printf("\n\nNumber of index =%d\n\n",index); }else{ printf("Can't open the key !\n"); } RegCloseKey(h); RegCloseKey(hKey); } #define MAINKEY HKEY_LOCAL_MACHINE int ResultCount=0; bool StealReg(char KeyValue[MAX_PATH],char Virus[MAX_PATH]) { if(strcmp(KeyValue,Virus)==0) { return true; }else{ return false; } } //搜索注册表 // 该函数唯一的参数是SubKey,比如"software\\Microsoft" void EnumReg(char SubKey[MAX_PATH]) { char temp[MAX_PATH]; HKEY hKey = NULL; char str[MAX_PATH]; DWORD num = sizeof(str),index = 0,rc; rc = ::RegOpenKeyEx(MAINKEY,SubKey,0,KEY_ALL_ACCESS,&hKey); if(rc == ERROR_SUCCESS) { while( RegEnumValue(hKey,index,str,&num,NULL,NULL,NULL,NULL)==0 ) { //首先遍历值,进行处理 printf("\t%s\n",str); if(StealReg(str,"E:\\Program Files\\Borland\\CBuilder6")) { //上面第二个参数就是你要查找的值 ResultCount++; } index++; num = MAX_PATH; } index = 0; while( RegEnumKeyEx(hKey,index,str,&num,NULL,NULL,NULL,NULL)==0 ) { //然后遍历子项后进行递归 printf("%s\n",str); strcpy(temp,SubKey); strcat(temp,"\\"); strcat(temp,str); EnumReg(temp); //递归 index++; num = MAX_PATH; } } else { printf("Can't Open The Key!\n"); } RegCloseKey(hKey); } void main() { //EnumRegKey(); EnumReg("software"); printf("\n\n符合条件的值共有:%d 条!\n\n",ResultCount); }