Enumerate registry values

Share your advanced PureBasic knowledge/code with the community.
User avatar
Keya
Addict
Addict
Posts: 1882
Joined: Thu Jun 04, 2015 7:10 am

Enumerate registry values

Post by Keya »

I was shocked that in 2015 there isn't a single code snippet at this forum that uses RegEnumValue_()! so here is my groundbreaking code, lol :D
[edit] Update - I was shocked to learn that in 2015 the Purebasic forum search engine is so useless it failed to miss the 23 actual instances it shouldve found! lol! what a waste of time :(... must use Google search from now on!

Im only using small 512 byte buffer though, if youre expecting larger values/data you might want to increase that! You can check the return value of RegEnumValue for that.

Code: Select all

Procedure EnumRegValues(RootHKEY.l, sKey.s) 
  Protected hKey.l
  If RegOpenKeyEx_(RootHKEY, sKey, 0, #KEY_READ, @hKey) = #ERROR_SUCCESS    
   idx.l = 0
   Repeat
     ValueName.s = Space(511):  ValueNameLen.l = Len(ValueName)
     ValueData.s = Space(511):  ValueDataLen.l = Len(ValueData)
     Retval.l = RegEnumValue_(hKey, idx, @ValueName, @ValueNameLen, #Null, @dwType, @ValueData, @ValueDataLen)
     If Retval <> #ERROR_SUCCESS
       Break
     EndIf
     ValueName = Left(ValueName, ValueNameLen)
     Select dwType
       Case #REG_SZ
         ValueData = Left(ValueData, ValueDataLen - 1)
       Default
         ValueData = "<Not REG_SZ>"
     EndSelect
     Debug(ValueName + " = " + ValueData)
     idx = idx + 1
   Until Retval <> #ERROR_SUCCESS
   RegCloseKey_(hKey)
 Else
   Debug("RegOpenKeyEx fail")
 EndIf
EndProcedure


EnumRegValues(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion")
Last edited by Keya on Wed Aug 12, 2015 5:12 pm, edited 1 time in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Enumerate registry values

Post by Dude »

Keya wrote:I was shocked that in 2015 there isn't a single code snippet at this forum that uses RegEnumValue_()!
Are you kidding? Look at these search results: http://www.google.com/search?q=regenumv ... fr/english
User avatar
Keya
Addict
Addict
Posts: 1882
Joined: Thu Jun 04, 2015 7:10 am

Re: Enumerate registry values

Post by Keya »

:(
so Google = 25 results for "RegEnumValue" at purebasic.fr
purebasic.fr forums own search = just 2 results... mine, and one other which didn't have code.

http://www.purebasic.fr/english/search. ... mit=Search
^ searching Messages+Titles for: RegEnumValue
(also "RegEnumValue_" yields same results)

I just learned to use wildcards at this forum search .... *RegEnumValue* found 22 results (but still not Google's 25)
Searching for "RegEnumValue" and "RegEnumValue_" on their own though shows how useless the whole-word searching algorithm is, and I'm sure most people would simply type just type in the word they're searching for without wildcards unless they've experienced like this how useless whole-word search is.
Guess i'll just use Google! :P (it seems there's already been a lot of discussion about forum search heehee)
Little John
Addict
Addict
Posts: 4074
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Enumerate registry values

Post by Little John »

Keya wrote:Guess i'll just use Google! :P
Look at my signature! :-)
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5066
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Enumerate registry values

Post by Kwai chang caine »

Look at my signature!
Good tips too :wink:
Thanks 8)
ImageThe happiness is a road...
Not a destination
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Enumerate registry values

Post by Dude »

Keya wrote:I just learned to use wildcards at this forum search .... *RegEnumValue* found 22 results (but still not Google's 25)
I searched for *RegEnumValue* and got 32 results here, 7 more than Google. :)
Post Reply