c++列挙と検索レジストリ

2166 ワード

#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 
",str); index++; num=MAX_PATH; } printf("

Number of index =%d

",index); }else{ printf("Can't open the key !
"); } 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
",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
",str); strcpy(temp,SubKey); strcat(temp,"\\"); strcat(temp,str); EnumReg(temp); // index++; num = MAX_PATH; } } else { printf("Can't Open The Key!
"); } RegCloseKey(hKey); } void main() { //EnumRegKey(); EnumReg("software"); printf("

:%d !

",ResultCount); }