8 Replies - 4128 Views - Last Post: 14 May 2010 - 02:24 PM Rate Topic: -----

#1 vBx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-May 10

Enumerate all keys and values in registry

Posted 14 May 2010 - 11:28 AM

hello i have 2 functions,one to enumerate keys in the registry,and one to enumerate values and datas in the registry and they are working fine,but i can`t seem to make it to work,when i enumerate a key to display the values for that key,and so on.... here is my two functions:

void Registry::print_keys(LPCSTR Value , DWORD index)
{
	if(index == 0)
	{
		cout << "----==== ENUMERATING KEYS FOR:" << Value << "====----" << endl;
	}
	cout << index << ":" << ValueName << endl;
}

void Registry::enum_key(HKEY Hkey , DWORD level)
{
	FILETIME filetime;
	int i = 0;
	size = MaxValueLen;
	BOOL bContinue = TRUE;

	do
	{
		lRet = RegEnumKeyEx(Hkey , i , ValueName , &size , 0 , 0 , 0 , &filetime);
		switch(lRet)
		{
		case ERROR_SUCCESS:
			print_keys(ValueName , i);
			//enum_value(Hkey);
			i++;
			size = MaxValueLen;
			HKEY subhkey;
			if(open_key_ex(Hkey , ValueName, subhkey))
			{
				enum_key(subhkey , level + 1);
				RegCloseKey(subhkey);
			}
			break;
		case ERROR_MORE_DATA:
			size = MaxValueLen;
			if(NULL != ValueName) delete [] ValueName;
			ValueName = new TCHAR[size];
			break;
		  case ERROR_NO_MORE_ITEMS:
			  bContinue = false;
			  break;
		  default:
			  cout << "Unexpected error: " << GetLastError() << endl;
			  bContinue = false;
			  break;
		}
	}while(bContinue);
}

void Registry::enum_value(HKEY Hkey)
{
	DWORD type = REG_NONE;
	int i = 0;
	BOOL bContinue = TRUE;

	do
	{
		lRet = RegEnumValue(Hkey , i , ValueName , &size , 0 , &type , ValueData , &size2);
		size = MaxValueLen;
		switch(lRet)
		{
		case ERROR_SUCCESS:
			print_values(ValueName , type , ValueData , size2);
			size2 = MaxDataLen;
			i++;
			break;
		case ERROR_MORE_DATA:
			MaxDataLen = size2;
			if(NULL != ValueData) delete [] ValueData;
			ValueData = new BYTE[MaxDataLen];
			break;
		case ERROR_NO_MORE_ITEMS:
			bContinue = false;
			break;
		default:
			cout << "Unexpected error: " << GetLastError() << endl;
			bContinue = false;
			break;
		}
	}while(bContinue);
}



where can i call enum_value() to display them corectly ? thanx

Is This A Good Question/Topic? 0
  • +

Replies To: Enumerate all keys and values in registry

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 12:22 PM

What do you mean where can you call it?

It looks like you have a Registry class somewhere. Declare and instance of the Registry class and call the function

int main()
{
  Registry reg;

  reg.enum_value(FUNCTION PARAMETERS);

  return 0;
}

Was This Post Helpful? 0
  • +
  • -

#3 vBx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-May 10

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:05 PM

but i need to call it inside the enum_keys() function so after it displays a key it must display here values,then another key and his values,and so on...
Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:13 PM

What's wrong with where you have it commented out?

It should print out for all keys in the loop. I'm not really understanding what you're saying.
Was This Post Helpful? 0
  • +
  • -

#5 vBx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-May 10

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:31 PM

if i leave it where i comment it,it prints a few keys (no values) and then it stops printing (program still running) if i comment that it prints all the keys.
Thats why i am confuse and not sure where to call enum_value()
Was This Post Helpful? 0
  • +
  • -

#6 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:38 PM

I don't know registry functions by heart and without having the full program to debug all I can suggest it that you open up the program and step through it line by line in the debugger.

If you don't have or no how to use a debugger then it's time to learn. That's essentially what I'd do. You would be able to solve more problems on your own as well.

If you don't have a debugger then I suggest getting the GDB debugger that works on all platforms
http://www.gnu.org/software/gdb/

Or if you are on a windows machine then your best option is to use Microsoft debugger built into all Visual Studio versions.

If you don't have Visual Studio then you can go to the Microsoft website and download the free express edition that contains a debugger as well.
http://www.microsoft...ress/downloads/
Was This Post Helpful? 0
  • +
  • -

#7 vBx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-May 10

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:46 PM

it would have been easy with a debugger,but it doesnt work for me,i try set it up i search google....and nothing....so i cant use it,i use eclipse :(
Was This Post Helpful? 0
  • +
  • -

#8 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 01:55 PM

Are you on Windows?

What do you mean set it up? You can't install it or you don't know how to use the actual program.
Believe me, it will be well worth your time to learn how to use a debugger. Even if coding is only a hobby. It's saves time and frustration.

If you don't know how to use it (Visual Studio) then look here:
http://www.dreaminco...al-studio-2008/

To debug your programs simply click on the left side of the textfield to place a break point and hit the play button. Then use the step into and step over debug function (step over is F11 I think)

If you post your entire program, I'll take a look at if for you but I can't promise anything.

This post has been edited by eker676: 14 May 2010 - 01:55 PM

Was This Post Helpful? 0
  • +
  • -

#9 vBx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-May 10

Re: Enumerate all keys and values in registry

Posted 14 May 2010 - 02:24 PM

no,it didnt work,it gave me a lauch error,but now i saw that i didnt say the path to gdb.exe,now is working...i know the debuger is a life saver. Thanks for help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1