Jump to content
OnePiece

_RegEnumKeyEx (Lists all subkeys in a specified registry key)

Recommended Posts

Ragazzi cercando in Autoit forum per un codice da leggere il registro, e non trovando niente, ecco o fato questo codice che sembra davvero OKKK, per chi usa AutoIt la troverà davvero tanto tanto utile


#RequireAdmin
#include <Array.au3>

$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft"
;$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

Ciao a tutti.

Edited by OnePiece

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

×