Jump to content
Sign in to follow this  

Read All Reg. Values into an array?

Recommended Posts



The thing I'm looking for, is a command that is able to scan a Registry key a map it's Values / it's datas. Is there such a UDF or do you know if a similar thread is already discussed? I tried to look for it but I failed :)

Well, Currently It's late night at me so all the things I say is just Theory and I can't test it, so I'm sorry if I say sg. wrong.

As I think I could solve it by using RegEnumVal and RegEnumKey, but this way I can't be sure that I mapped all the values. If no other idea / solution exist, my one is this:

Loop the instances of the RegEnumVal, so it will return all the keys. The datas can be read by using simple regread, but my only problem is that I can't know the maximum value of the "instance".

Thats quite a noob solution, that's why I'm asking for a better one :) I hope you can give me a better one :)

[ Well I can loop it 200 times if it's really needed... It just looks weird that it "bruteforces" the registry :) ]

~ I hope you could understand me. Gonna answer tomorrow!

~ Now have to sleep, BB.

Edited by Unc3nZureD

Share this post

Link to post
Share on other sites

You can use RegEnumKey and RegEnumVal without having to know the maximum number of entries in the list. Here's a simple demonstration of what I mean.

For $i = 30 To 110
     Local $var = RegEnumKey("HKEY_LOCAL_MACHINESOFTWARE", $i)
     If @error <> 0 Then
          ConsoleWrite("Error encountered: when $i = " & $i & @CRLF)
     ConsoleWrite("SubKey #" & $i & " under HKLMSoftware: " & $var & @CRLF)

NOTE: This was taken from the help file example script for RegEnumKey and modified slightly.

BTW, you'd have to create a recursive/iterative registry search routine so that you are sure you're getting all the subkeys and their values. It would be similar to the numerous recursive FileListToArray functions floating around here.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

At night I was thinking and I had a very similar idea :)

This one:

$i = 0

While 1
   $i = $i + 1
   $reg = RegEnumVal("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun", $i)
   If @error <> 0 Then ExitLoop
   MsgBox(0,"",$reg & " " & @error)


Anyways thanks!

Share this post

Link to post
Share on other sites

Hi Unc3nZureD try this


apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post

Link to post
Share on other sites

Try this, using the Country List as an example.

#include <Array.au3>

Dim $regKey = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionTelephonyCountry List"

Global $arKeys = _EnumRegKeys2Array($regKey)


;~ For $i = 1 To _EnumRegKeys2Array($regKey)
;~     ConsoleWrite($i & @CRLF)
;~ Next

Func _EnumRegKeys2Array($sRegKey)
    Local Const $REG_NONE = 0
    Local Const $REG_SZ = 1
    Local Const $REG_EXPAND_SZ = 2
    Local Const $REG_BINARY = 3
    Local Const $REG_DWORD = 4
    Local Const $REG_DWORD_BIG_ENDIAN = 5
    Local Const $REG_LINK = 6
    Local Const $REG_MULTI_SZ = 7
    Local Const $REG_RESOURCE_LIST = 8
    Local Const $REG_QWORD = 11 ; Vista

    Local $aResult[1][3], $aResult_sub, $i, $y
    Local $sRegKey_Name, $sRegKey_Value, $sRegKey_Type

    If StringRight($sRegKey, 1) <> "" Then $sRegKey = $sRegKey & ""
    $aResult[0][0] = "0"

    $i = 1
    While 1
        $sRegKey_Name = RegEnumVal($sRegKey, $i)
        If @error Then ExitLoop
        ReDim $aResult[UBound($aResult) + 1][3]
        $aResult[UBound($aResult) - 1][0] = $sRegKey & $sRegKey_Name
        $sRegKey_Value = RegRead($sRegKey, $sRegKey_Name)
        $sRegKey_Type = @extended

        If $sRegKey_Type = $REG_NONE Then $sRegKey_Type = "REG_NONE"
        If $sRegKey_Type = $REG_SZ Then $sRegKey_Type = "REG_SZ"
        If $sRegKey_Type = $REG_EXPAND_SZ Then $sRegKey_Type = "REG_EXPAND_SZ"
        If $sRegKey_Type = $REG_BINARY Then $sRegKey_Type = "REG_BINARY"
        If $sRegKey_Type = $REG_DWORD Then $sRegKey_Type = "REG_DWORD"
        If $sRegKey_Type = $REG_DWORD_BIG_ENDIAN Then $sRegKey_Type = "REG_DWORD_BIG_ENDIAN"
        If $sRegKey_Type = $REG_LINK Then $sRegKey_Type = "REG_LINK"
        If $sRegKey_Type = $REG_MULTI_SZ Then $sRegKey_Type = "REG_MULTI_SZ"
        If $sRegKey_Type = $REG_RESOURCE_LIST Then $sRegKey_Type = "REG_RESOURCE_LIST"
        If $sRegKey_Type = $REG_QWORD Then $sRegKey_Type = "REG_QWORD" ; Vista

        $aResult[UBound($aResult) - 1][1] = $sRegKey_Value
        $aResult[UBound($aResult) - 1][2] = $sRegKey_Type
        $i += 1

    $i = 1
    While 1
        $sRegKey_Name = RegEnumKey($sRegKey, $i)
        If @error Then ExitLoop
        $aResult_sub = _EnumRegKeys2Array($sRegKey & $sRegKey_Name)
        If UBound($aResult_sub) > 1 Then
            For $y = 1 To UBound($aResult_sub) - 1
                ReDim $aResult[UBound($aResult) + 1][3]
                $aResult[UBound($aResult) - 1][0] = $aResult_sub[$y][0]
                $aResult[UBound($aResult) - 1][1] = $aResult_sub[$y][1]
                $aResult[UBound($aResult) - 1][2] = $aResult_sub[$y][2]
        $i += 1

    $aResult[0][0] = UBound($aResult) - 1
    Return $aResult

EndFunc   ;==>_EnumRegKeys2Array

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this