WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Registry
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Using RegQueryKeys and Counting the Number of Subkeys

Keywords:     regquerykeys

Question:

I am writing a program that searches through the registry to find different types of keys.

Well, I use these three lines to search for subkeys within the current key that I am in:

	keylevel = RegOpenKey(@REGMACHINE,string)
	string1 = RegQueryKeys(keylevel)
	RegCloseKey(keylevel)
When dealing with the registry - some of the subkeys can be extremely long - One of them was 470 subkeys - so thats 470 long strings delimited by @tab

Anyways, because of this I get Error 3096 - Memory Allocation Error. Out of Memory for Strings. This always happens when trying to extract one of the values from this super long list within a string.

Answer:

You are going to have to use RegQueryKey (Singlular) and grab the keys one at a time.

Here's an example:

	mainkey="SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\"
	subkeylist=RegQueryKeys(@REGMACHINE,mainkey)
	count=ItemCount(subkeylist,@tab)
	
	for xx=1 to count
	   thissubkey=ItemExtract(xx,subkeylist,@tab)
	   srvkey= strcat(mainkey,thissubkey, "[servicename]"
	   thisname=RegQueryValue(@REGMACHINE,srvkey)
	   Message(thissubkey,thisname)
	next

Before 97A came out with RegQueryKeys, you could do the following:

	regkey = RegOpenKey (@REGCURRENT, "wherever")
	l_REG_subkeys = ""
	For regcounter = 0 To 9999 ; Run through all subkeys (arbitrarily high number)
	mysubkey = RegQueryKey (regkey, regcounter)
	If (mysubkey == "") Then Break
	; do actions on mysubkey or break if the
	; right one found, depending on need.
	Next
	RegCloseKey (regkey)
Because we were not working with the vast numbers of keys that you are, we switched to the cleaner RegQueryKeys as soon as we found it, but the above will work for your needs.
Article ID:   W13735
Filename:   RegQueryKeys and Counting Subkeys.txt
File Created: 1999:04:15:16:56:02
Last Updated: 1999:04:15:16:56:02