Docfxit

Lists all subkeys in a specified registry key

4 posts in this topic

I found a script created by  OnePiece   at:

'?do=embed' frameborder='0' data-embedContent>>

Called       _RegEnumKeyEx (Lists all subkeys in a specified registry key)

Does anyone know why this won't work with my registry key?

#RequireAdmin
#include <Array.au3>

$KeyName = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\SW\DiskSuperSpeed_RamDisk_9_0"
;$KeyName = "HKEY_CLASSES_ROOT" ;104718
;$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes"

Global $a1, $b1
$a1 = TimerInit()
$b1 = _RegEnumKeyEx($KeyName, 0, "Opti*Components") ; to find HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OptionalComponents
$a1 = TimerDiff($a1)
_ArrayDisplay($b1, $a1)


; #FUNCTION# ========================================================================================================================
; Name...........: _RegEnumKeyEx
; Description ...: Lists all subkeys in a specified registry key
; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]])
; Parameters ....: $KeyName - The registry key to read.
; $iFlag - Optional specifies Recursion
; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod
; |$iFlag = 1 All SubKeys Not Recursive Mod
; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ")
; Search the Autoit3 helpfile for the word "WildCards" For details.
; Return values .: Success - Return Array List (See Remarks)
; Failure - @Error
; |1 = Invalid $sFilter
; |2 = No Key-SubKey(s) Found
; Author ........: DXRW4E
; Modified.......:
; Remarks .......: The array returned is one-dimensional and is made up as follows:
; $array[0] = Number of Key-SubKeys returned
; $array[1] = 1st Key\SubKeys
; $array[2] = 2nd Key\SubKeys
; $array[3] = 3rd Key\SubKeys
; $array[n] = nth Key\SubKeys
; Related .......:
; Link ..........:
; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3")
; Note ..........:
; ===================================================================================================================================
Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*")
If StringRegExp($sFilter, "[\\/:><]|(?s)\A\s*\z") Then Return SetError(1, 0, "")
Local $DX_REKI[101] = [100], $DX_REKISN, $BS = "\", $DX_REKNL, $I = 1, $DX_Filter = StringRegExpReplace($sFilter, "[\*\s]+", ""), $DX_REKFilter = "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sFilter & "|", '\|\h*\|[\|\h]*', "\|"), '[\^\$\(\)\+\[\]\{\}\,\.\]', "\\$0"), "\|([^\*])", "\|^$1"), "([^\*])\|", "$1\$\|"), '\*', ".*"), '^\||\|$', "") & ")"
While $I
$DX_REKI[$I] += 1
$DX_REKISN = RegEnumKey($KeyName, $DX_REKI[$I])
If @error Then
$DX_REKI[$I] = 0
$I -= 1
$KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1)
ContinueLoop
EndIf
If $DX_Filter Then
If StringRegExp($DX_REKISN, $DX_REKFilter) Then $DX_REKNL &= @LF & $KeyName & $BS & $DX_REKISN
Else
$DX_REKNL &= @LF & $KeyName & $BS & $DX_REKISN
EndIf
If $iFlag Then ContinueLoop
$I += 1
If $I > $DX_REKI[0] Then
$DX_REKI[0] += 100
ReDim $DX_REKI[$DX_REKI[0] + 1]
EndIf
$KeyName &= $BS & $DX_REKISN
WEnd
If Not $DX_REKNL Then Return SetError(2, 0, "")
Return StringSplit(StringTrimLeft($DX_REKNL, 1), @LF)
EndFunc

Thank you,

Docfxit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi Docfxit, AutoIt Forum ???????

recommended RegistryEx.au3 is slower but is more safer

 

RegistryEx.au3 is much faster and more secure in comparison with the SetACL or any other way, with RegistryEx.au3 no need to check and after taking permission of the Registry key and after Edit Registry etc etc and after restore original permissions ;) in poor words with RegistryEx.au3 do not matter if you have or do not have permission of the registry key, _WinAPI_RegOpenKey (always open a Key) and _WinAPI_RegDeleteValue always delete the Value etc etc etc _WinAPI_Reg*** always edit Registry without changing the original security permissions

Ciao.

Edited by DXRW4E

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

#3 ·  Posted (edited)

Thank you for pointing that out.

I just can't figure out how to program this function:

#RequireAdmin
#include <winapireg.au3>
If NOT IsDeclared("ERROR_SUCCESS") Then Global Const $ERROR_SUCCESS = 0
$iIndex = 0
$s = 1
Do
    $subKey[$s] = _WinAPI_RegEnumKey($RegistryEntry3, $iIndex)
        $iIndex = $iIndex + 1
Until Not ERROR_SUCCESS
For $t = 1 To $subKey[0]
    $MsgBoxText = $MsgBoxText & $t & " " & $subKey[$i] & @CRLF
Next

error: ERROR_SUCCESS(): undefined function.

Thanks,

Docfxit

Edited by Docfxit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi Docfxit

1  - What is $RegistryEntry3 ??? you have to give a concrete example of what you want to do ??, because in the code you're using the $RegistryEntry3 will have to be a registry handle, and I do not think is so

2 - I'll have suggested Many Times for Many Reasons to use the RegistryEx.au3 ?????????

3 - What we do not understand or difficult here ?????

#include "RegistryEx.au3"
#include <Array.au3>

Local $sRegKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe", $aRegKey

$aRegKey = _WinAPI_RegEnumKeyEx(Null, $sRegKeyPath)
If Not @Error Then
    _ArrayDisplay($aRegKey)
EndIf

;;;; from _WinAPI_RegEnumKeyEx  parameter
;                  $iFlags  - Optional specifies Recursion (add the flags together for multiple operations):
;                  |$iFlags = 0 (Default) All Key-SubKeys Recursive Mod
;                  |$iFlags = 1 All SubKeys Not Recursive Mod
;                  |$iFlags = 2 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound()
;                  |              to get the size in this case). By Default the first element ($array[0]) contains the number of
;                  |              keys\subkeys\values returned, the remaining elements ($array[1], $array[2], etc.)
;                  |  These flags are ignored by 32-bit Windows
;                  |$iFlags = 256 operate on the 64-bit registry view, $KEY_WOW64_64KEY (256)
;                  |$iFlags = 512 operate on the 32-bit registry view, $KEY_WOW64_32KEY (512)
$aRegKey = _WinAPI_RegEnumKeyEx(Null, $sRegKeyPath, 1) ; All SubKeys Not Recursive Mod
If Not @Error Then
    _ArrayDisplay($aRegKey)
EndIf

$aRegKey = _WinAPI_RegEnumKeyEx(Null, $sRegKeyPath, 1 + 2) ; All SubKeys Not Recursive Mod + Disable the return the count in the first element
If Not @Error Then
    _ArrayDisplay($aRegKey)
EndIf

$aRegKey = _WinAPI_RegEnumKeyEx(Null, $sRegKeyPath, 0 + 256) ; All Key-SubKeys Recursive Mod + operate on the 64-bit registry view
If Not @Error Then
    _ArrayDisplay($aRegKey)
EndIf

local $aRegValue = _WinAPI_RegEnumValueEx(Null, $sRegKeyPath)
If Not @Error Then
    _ArrayDisplay($aRegValue)
Else
    MsgBox(0, 1, @Error)
EndIf

;;;; Or
Local $hKey, $sSubKey, $dwIndex = 0

$hKey = _WinAPI_RegOpenKey(Null, $sRegKeyPath, $KEY_ALL_ACCESS + 256) ;$KEY_WOW64_64KEY (256)
If Not @Error Then
    Do
        $sSubKey = _WinAPI_RegEnumKey($hKey, $dwIndex)
        $dwIndex += 1
    Until @Error
EndIf
_WinAPI_RegCloseKey($hKey)

;;;; Or
$dwIndex = 0
$hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, "SOFTWARE\Adobe", $KEY_ALL_ACCESS)
While (Not  @Error)
    $sSubKey = _WinAPI_RegEnumKey($hKey, $dwIndex)
    $dwIndex += 1
WEnd
_WinAPI_RegCloseKey($hKey)

Ciao.

Edited by DXRW4E

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

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