Jump to content

Recommended Posts

Posted (edited)

I was in need of a function to enumerate registry keys including all sub-keys and couldn't find one...

#include<Array.au3>

$aResult = _EnumRegKeys2Array("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run")
_ArrayDisplay($aResult)

$aResult = _EnumRegKeys2Array("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
_ArrayDisplay($aResult)


;===============================================================================
;
; Function Name:    _EnumRegKeys2Array()
; Version:          v0.2
; Description:      Create an Array of all registry keys and sub-keys at the pointed location
; Parameter(s):     $sRegKey        - Start Key to enumerate including any sub-keys
; Return Value(s):  On Success  - Returns an array with RegKeys Name, Value & Type
;                   On Failure  - No error checking yet...
; Author(s):        KaFu
; URL:              http://www.autoitscript.com/forum/index.php?showtopic=85661
; Last modified:    2008-Dec-22
;
;===============================================================================
;
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_FULL_RESOURCE_DESCRIPTOR = 9
    Local Const $REG_RESOURCE_REQUIREMENTS_LIST = 10
    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_FULL_RESOURCE_DESCRIPTOR then $sRegKey_Type = "REG_FULL_RESOURCE_DESCRIPTOR"
        if $sRegKey_Type = $REG_RESOURCE_REQUIREMENTS_LIST then $sRegKey_Type = "REG_RESOURCE_REQUIREMENTS_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
    WEnd

    $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]
            next
        EndIf
        $i += 1
    WEnd

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

EndFunc

Best Regards

Edit: Added 2nd Example.

Edited by KaFu
  • 2 weeks later...
Posted

@Kafu,

Thank you very much

Just what i was looking for

Best regards,

Emiel

There is always someone searching for udf and... hop its here, what a coincidence :) ... :o

@Kafu

Nice work :D

Posted

Very nice. Been waiting for somebody to make something like this for a long time.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Posted

Qword values exist on XP Pro SP2 as well. Here is a list of what I have found. This gives the flag for INF syntax both long and abbreviated, as well as the flag for exported .reg files.

REG_DELETE =-

REG_SZ 0x00000000 0x0 =""

REG_SZ *special unknown* =hex(1):

REG_DWORD 0x00010001 0x10001 =dword:

REG_BINARY 0x00000001 0x1 =hex:

REG_NONE 0x00020001 0x20001 =hex(0):

REG_EXPAND_SIZE 0x00020000 0x20000 =hex(2):

REG_MULTI_SZ 0x00010000 0x10000 =hex(7):

REG_RESOURCE_LIST 0x00080001 0x80001 =hex(8):

REG_FULL_RESOURCE_DESCRIPTOR 0x00090001 0x90001 =hex(9):

REG_RESOURCE_REQUIREMENTS_LIST 0x000A0001 0xA0001 =hex(a):

REG_QWORD 0x000B0001 0xB0001 =hex(b ):

REG_LINK

REG_DWORD_BIG_ENDIAN

I have never seen a value for REG_LINK or REG_DWORD_BIG_ENDIAN in xp .reg files or .inf files. There is one other type of file you have not seen, a hex(1). This is a REG_SZ, but exported as hex(1). This is similar to a REG_MULTI_SZ, but different. I have only found it in one reg location, for the old f-prot v3 antivirus. Somehow InstallShield was able to create this value, and after weeks of trying to figure out this last known (to me) reg value type, I could only get it to merge into the registry via a .reg file. I could never find the flag. I tried every combination of 0x00000000 I could put together. It still remains a myster to this day for me.

Sul.

  • 3 weeks later...
  • 1 year later...
Posted

Hey, I try to make a listview display it but fail :blink: Can you give me some point?

Eg:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$URL = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"

$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$ListView = GUICtrlCreateListView("Name|Type|Data", 16, 24, 602, 406,BitOR($LVS_REPORT,$LVS_EDITLABELS,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTDESCENDING))
        _GUICtrlListView_SetUnicodeFormat($ListView, True)
        _GUICtrlListView_SetColumnWidth($ListView, 0, 120)
        _GUICtrlListView_SetColumnWidth($ListView, 1, 50)
        _GUICtrlListView_SetColumnWidth($ListView, 2, 200)
$Result = _EnumRegKeys2Array($URL)
_Example1()
;_Example2()
Func _Example1()
For $i = 1 to $Result[0][0]
        ;_GUICtrlListView_SetItemImage($ListView,0, "C:\Documents and Settings\HippyNotRight\Desktop\New Folder\RegEdit\REG_SZ.ico")
        _GUICtrlListView_AddItem($ListView,$Result[$i][0],$i)
        _GUICtrlListView_AddSubItem($ListView,0,$Result[$i][2],1,1)
        _GUICtrlListView_AddSubItem($ListView, 0,$Result[$i][1],2,2)
Next
GUISetState(@SW_SHOW)
EndFunc


Func _Example2()
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))
    _GUICtrlListView_AddArray($ListView,$Result)
GUISetState(@SW_SHOW)
EndFunc

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


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_FULL_RESOURCE_DESCRIPTOR = 9
    Local Const $REG_RESOURCE_REQUIREMENTS_LIST = 10
    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_FULL_RESOURCE_DESCRIPTOR then $sRegKey_Type = "REG_FULL_RESOURCE_DESCRIPTOR"
        if $sRegKey_Type = $REG_RESOURCE_REQUIREMENTS_LIST then $sRegKey_Type = "REG_RESOURCE_REQUIREMENTS_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
    WEnd

    $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]
            next
        EndIf
        $i += 1
    WEnd

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

EndFunc

You can see the Eg1 and Eg2 not display the Array correctly. How can i display $result to a Listview?

another Question: How can i add an icon to a Listview Item?

Thanks in advanced!

4m848p10.gif 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...