Voila ma dernière fonction:
_Reg_Search()
Elle permet faire des recherche sur la base de registre, à la manière des fonction _FileListToArray()
Elle retourne un array de forme [x][3]
[x][0] = Nom de l'entrée/Chemin complet (selon $iReturnFullPath)
[x][1] = Valeur de l'entrée
[x][2] = Type de l'entrée (String: comme celui de RegWrite - REG_SZ, REG_DWORD ...)
Au fait, je cherche un coup de main, ce que j'aimerai faire:
- Recherche récursives supérieurs à 1 seul niveau
- Peut être aussi (je n'ai pas essayé, je vient d'avoir l'idée) de pouvoir choisir entre rechercher des clef ou des entrées
La fonction:
► Afficher le texte
Code : Tout sélectionner
#include-once
#region ### Exemple ###
#include <Array.au3>
$a = _Reg_Search("HKLM\Software\Microsoft\Windows\CurrentVersion\Run")
_ArrayDisplay($a)
#endregion
; Array: name, value, type
#cs
Paramtres:
$sKey = Chemin de la clef à explorer
$sFilterName = Filtre de nom de l'entré du registre
$sFilterValue = Filtre de valeur
$sFilterType = Filtre de type (comme dans RegWrite)
$iReturnFullPath = 0 - Retourne seulement les noms des valeurs
1 - Retourne le chemin complet vers la valeur
$iRecurse = Recherche récursive (ne prend en charge qu'un seul niveau)
#ce
Func _Reg_Search($sKey, $sFilterName = "*", $sFilterValue = "*", $sFilterType = "*", $iReturnFullPath = 0, $iRecurse = 0)
Local $aRet[1][3] ; name, value, type
$aRet[0][0] = 0
; ---
Local $SRE_Name = _RFLTA_ListToMask($sFilterName)
Local $SRE_Val = _RFLTA_ListToMask($sFilterValue)
Local $SRE_Type = _RFLTA_ListToMask($sFilterType)
; ---
; Search the first key
__Reg_Search_SearchKey($sKey, $aRet, $SRE_Name, $SRE_Val, $SRE_Type, $iReturnFullPath)
; ---
Local $x = 1, $key
If $iRecurse Then
While 1
$key = RegEnumKey($sKey, $x)
If @error Then ExitLoop
; ---
__Reg_Search_SearchKey($sKey & "\" & $key, $aRet, $SRE_Name, $SRE_Val, $SRE_Type, $iReturnFullPath)
; ---
$x += 1
WEnd
EndIf
; ---
Return $aRet
EndFunc
; ==============================================================
; ### Internals
; ==============================================================
Func __Reg_Search_SearchKey($sKey, ByRef $aRet, $SRE_Name, $SRE_Val, $SRE_Type, $iReturnFull)
ConsoleWrite("Searching Key: " & $sKey & @CRLF)
Local $i = 1, $name
While 1
$name = RegEnumVal($sKey, $i)
If @error Then ExitLoop
; ---
__Reg_Search_AddResult($aRet, $sKey, $name, $SRE_Name, $SRE_Val, $SRE_Type, $iReturnFull)
$i += 1
WEnd
EndFunc
Func __Reg_Search_AddResult(ByRef $array, $key, $name, $SRE_Name, $SRE_Val, $SRE_Type, $iReturnFull)
Local $value = RegRead($key, $name)
Local $type = __Reg_Search_ConstToStr(@extended)
; ---
If StringRegExp($name, $SRE_Name) And StringRegExp($value, $SRE_Val) And StringRegExp($type, $SRE_Type) Then
ConsoleWrite(" Adding Result: " & $name & " => " & $value & @CRLF)
ReDim $array[$array[0][0] + 2][3]
If $iReturnFull Then
$array[$array[0][0] + 1][0] = $key & "\" & $name
Else
$array[$array[0][0] + 1][0] = $name
EndIf
$array[$array[0][0] + 1][1] = $value
$array[$array[0][0] + 1][2] = $type
$array[0][0] += 1
EndIf
; ---
Return
EndFunc
Func __Reg_Search_ConstToStr($const)
Local $ret
Switch $const
Case 0
$ret = "REG_NONE"
Case 1
$ret = "REG_SZ"
Case 2
$ret = "REG_EXPAND_SZ"
Case 3
$ret = "REG_BINARY"
Case 4
$ret = "REG_DWORD"
Case 5
$ret = "REG_DWORD_BIG_ENDIAN"
Case 6
$ret = "REG_LINK"
Case 7
$ret = "REG_MULTI_SZ"
Case 8
$ret = "REG_RESOURCE_LIST"
Case 9
$ret = "REG_FULL_RESOURCE_DESCRIPTOR"
Case 10
$ret = "REG_RESOURCE_REQUIREMENTS_LIST"
EndSwitch
; ---
Return $ret
EndFunc
; From RecFileListToArray.au3
Func _RFLTA_ListToMask($sList)
; Check for invalid characters within list
If StringRegExp($sList, "\\|/|:|\<|\>|\|") Then Return 0
; Strip WS and insert | for ;
$sList = StringReplace(StringStripWS(StringRegExpReplace($sList, "\s*;\s*", ";"), 3), ";", "|")
; Convert to SRE pattern
$sList = StringReplace(StringReplace(StringRegExpReplace($sList, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?")
; Add prefix and suffix
Return "(?i)^(" & $sList & ")\z"
EndFunc ;==>_RFLTA_ListToMask