Перечисление всех ключей в реестре

Простой пример для перечисления всех ключей в реестре.
Платформы: Windows
Автор: Amundo. Написано в 2009 году.

ключи реестра

#INCLUDE Once "windows.bi"

#INCLUDE Once "win/winreg.bi"


Declare Sub RecurseEnumKeys(hKey As HKEY, level As DWORD)
Declare Sub EnumValues(hKey As HKEY, level As DWORD)


Sub RecurseEnumKeys(hKey As HKEY, level As DWORD)
        Dim As DWORD dwIdx=0

        Dim As FILETIME fTime
        While TRUE
                Dim As ZString*MAX_PATH szKeyName
                Dim As DWORD dwKeySize=MAX_PATH
                If(RegEnumKeyEx(hKey, dwIdx, szKeyName, @dwKeySize, NULL, NULL, NULL, @fTime) <> ERROR_SUCCESS) Then Exit While

                Print Space(level*2); "KeyName: "; szKeyName
                dwIdx+=1

                Dim As HKEY hSubKey
                If RegOpenKeyEx(hKey, szKeyName, 0, KEY_READ, @hSubKey) = ERROR_SUCCESS Then

                        ' See if this has values
                        EnumValues(hSubKey, level)
                        RecurseEnumKeys(hSubKey, level+1)
                        RegCloseKey(hSubKey)
                End If

        Wend

End Sub


Sub EnumValues(hKey As HKEY, level As DWORD)
        ' "level" only passed for pretty-printing purposes
        Dim As DWORD dwIdx=0

        Dim As ZString*MAX_PATH szValueName
        Dim As DWORD dwValueSize=MAX_PATH
        While TRUE
                If(RegEnumValue(hKey, dwIdx, szValueName, @dwValueSize, NULL, NULL, NULL, NULL) = ERROR_NO_MORE_ITEMS) Then Exit While

                If szValueName = "" Then szValueName = "(Default)"
                Print Space(level*2+2); "ValueName: "; szValueName
                dwIdx+=1

                dwValueSize=MAX_PATH
        Wend

End Sub




Print

Print

Print "===================================================="
Print

Print


Dim As HKEY hKey

If RegOpenKeyEx(HKEY_LOCAL_MACHINE, ("SOFTWARE\Microsoft\Internet Explorer"), 0, KEY_ENUMERATE_SUB_KEYS, @hKey) = ERROR_SUCCESS Then

        RecurseEnumKeys(hKey, 0)
        RegCloseKey(hKey)
Endif

Print

Print "Program terminated, bye!"
Print

Sleep

ExitProcess(0)
End