Sign in to follow this  
Followers 0
Bodman

Read from Registry to Array

3 posts in this topic

Hi All,

I am trying to read the regkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run and display the result in a array. I nearly have this working as it builds a array of 2 columns and the correct length but only the last entry of the registry is displayed. Can anyone point me in the right direction please

#include <array.au3>
Global $RegTot=""

For $i = 1 to 100
    $var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
    If @error <> 0 then ExitLoop
    $var1 = Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $var)


ConsoleWrite ($var)
ConsoleWrite ($var1)
Global $Regtot[2][$i] = [[$Var], [$Var1]]

Next

_ArrayDisplay($Regtot, "Output", -1, 1)

$RegTot = ""

Share this post


Link to post
Share on other sites



Bodman,

You are constantly redeclaring your array inside the loop, so it only ever contains the final values. You need to use ReDim like this: ;)

#include <array.au3>
Global $RegTot[1][2] = [[0, 0]]

For $i = 1 To 100
    $var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $i)
    If @error <> 0 Then ExitLoop
    $var1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $var)

    ConsoleWrite($var)
    ConsoleWrite($var1)

    ; Resize the array while keeping existing elements
    ReDim $RegTot[$i + 1][2]
    $RegTot[$i][0] = $var
    $RegTot[$i][1] = $var1

Next

_ArrayDisplay($RegTot, "Output", -1, 1)

All clear? :huh2:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Brilliant thank you, I was going around the bend trying to work this out :huh2:

I looked at ReDim, but wasnt sure how to apply it.

Thanks again

Bodman

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  
Followers 0