GaryFrost Posted August 11, 2006 Posted August 11, 2006 (edited) expandcollapse popupOpt("MustDeclareVars", 1) _Main() Func _Main() Local $a_keys = _RegEnumValues(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"), $x ;~ Local $a_keys = _RegEnumValues(".", "HKLM", "test"), $x If Not @error Then For $x = 0 To UBound($a_keys) - 1 ConsoleWrite($a_keys[$x][0] & @TAB & ":" & @TAB & $a_keys[$x][1] & @TAB & ":" & @TAB & $a_keys[$x][2] & @LF) Next EndIf EndFunc ;==>_Main ;=============================================================================== ; ; Description: _RegEnumValues ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns a multi-dimensional array ([0] = key name, [1] = key value, [2] = key type) ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumValues(computer name, registry tree, sub key name) Enumerates the values of the given subkey ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumValues($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG = 0x80000005 If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $a_Type[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", "", "", "REG_MULTI_SZ"] Local $arrValueNames, $arrValueTypes Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumValues ($s_hDefKey, $strKeyPath, $arrValueNames, $arrValueTypes) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Local $a_ret[UBound($arrValueNames) ][3] For $x = 0 To UBound($arrValueNames) - 1 $a_ret[$x][0] = $arrValueNames[$x] $a_ret[$x][1] = RegRead($s_hDefKey & "\" & $strKeyPath, $arrValueNames[$x]) $a_ret[$x][2] = $a_Type[$arrValueTypes[$x]] Next Return $a_ret EndFunc ;==>_RegEnumValues Enjoy!!! Edited June 8, 2007 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted August 12, 2006 Author Posted August 12, 2006 (edited) Think _RegEnumKeys compliments _RegEnumValues nicely: expandcollapse popupOpt("MustDeclareVars", 1) _Main() Func _Main() Local $a_subkeys = _RegEnumKeys(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion"), $x, $y, $a_keys If Not @error Then For $x = 0 To UBound($a_subkeys) - 1 _DebugPrint($a_subkeys[$x]) $a_keys = _RegEnumValues(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\" & $a_subkeys[$x]) If Not @error Then For $y = 0 To UBound($a_keys) - 1 ConsoleWrite($a_keys[$y][0] & @TAB & ":" & @TAB & $a_keys[$y][1] & @TAB & ":" & @TAB & $a_keys[$y][2] & @LF) Next EndIf Next EndIf EndFunc ;==>_Main ;=============================================================================== ; ; Description: _RegEnumValues ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns a multi-dimensional array ([0] = key name, [1] = key value, [2] = key type) ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumValues(computer name, registry tree, sub key name) Enumerates the values of the given subkey ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumValues($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG = 0x80000005 If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $a_Type[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", "", "", "REG_MULTI_SZ"] Local $arrValueNames, $arrValueTypes Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumValues ($s_hDefKey, $strKeyPath, $arrValueNames, $arrValueTypes) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Local $a_ret[UBound($arrValueNames) ][3] For $x = 0 To UBound($arrValueNames) - 1 $a_ret[$x][0] = $arrValueNames[$x] $a_ret[$x][1] = RegRead($s_hDefKey & "\" & $strKeyPath, $arrValueNames[$x]) $a_ret[$x][2] = $a_Type[$arrValueTypes[$x]] Next Return $a_ret EndFunc ;==>_RegEnumValues ;=============================================================================== ; ; Description: _RegEnumKeys ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns An array of subkey strings ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumKeys(computer name, registry tree, sub key name) Enumerates the subkeys for a path ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumKeys($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG = 0x80000005 If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $arrValueNames Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumKey ($s_hDefKey, $strKeyPath, $arrValueNames) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Return $arrValueNames EndFunc ;==>_RegEnumKeys Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "!===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "!===========================================================" & @LF) EndFunc ;==>_DebugPrint Edited June 8, 2007 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
petesa Posted April 10, 2007 Posted April 10, 2007 Strange; for some reason the 'en _RegEnumValues' function is dropping and or changing the order of registry values? expandcollapse popupOpt("MustDeclareVars", 1) _Main() Func _Main() Local $a_subkeys = _RegEnumKeys(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"), $x, $y, $a_keys If Not @error Then For $x = 0 To UBound($a_subkeys) - 1 _DebugPrint($a_subkeys[$x]) $a_keys = _RegEnumValues(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $a_subkeys[$x]) If Not @error Then For $y = 0 To UBound($a_keys) - 1 ConsoleWrite($a_keys[$y][0] & @TAB & ":" & @TAB & $a_keys[$y][1] & @TAB & ":" & @TAB & $a_keys[$y][2] & @LF) Next EndIf Next EndIf EndFunc ;==>_Main ;=============================================================================== ; ; Description: _RegEnumValues ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns a multi-dimensional array ([0] = key name, [1] = key value, [2] = key type) ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumValues(computer name, registry tree, sub key name) Enumerates the values of the given subkey ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumValues($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $a_Type[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", "", "", "REG_MULTI_SZ"] Local $arrValueNames, $arrValueTypes Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumValues ($HKEY_LOCAL_MACHINE, $strKeyPath, $arrValueNames, $arrValueTypes) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Local $a_ret[UBound($arrValueNames) ][3] For $x = 0 To UBound($arrValueNames) - 1 $a_ret[$x][0] = $arrValueNames[$x] $a_ret[$x][1] = RegRead($s_hDefKey & "\" & $strKeyPath, $arrValueNames[$x]) $a_ret[$x][2] = $a_Type[$arrValueTypes[$x]] Next Return $a_ret EndFunc ;==>_RegEnumValues ;=============================================================================== ; ; Description: _RegEnumKeys ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns An array of subkey strings ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumKeys(computer name, registry tree, sub key name) Enumerates the subkeys for a path ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumKeys($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $a_Type[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", "", "", "REG_MULTI_SZ"] Local $arrValueNames, $arrValueTypes Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumKey ($HKEY_LOCAL_MACHINE, $strKeyPath, $arrValueNames) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Return $arrValueNames EndFunc ;==>_RegEnumKeys Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "!===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "!===========================================================" & @LF) EndFunc ;==>_DebugPrint
GaryFrost Posted April 11, 2007 Author Posted April 11, 2007 (edited) Can't help the order, it's not dropping any as far as I can tell, just wasn't a recursive function to drill down. example: expandcollapse popupOpt("MustDeclareVars", 1) _Main() Func _Main() _EnumKeys(".", "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion") EndFunc ;==>_Main Func _EnumKeys($strComputer, $s_hDefKey, $strKeyPath) Local $a_subkeys = _RegEnumKeys($strComputer, $s_hDefKey, $strKeyPath), $x, $y, $a_keys If Not @error Then For $x = 0 To UBound($a_subkeys) - 1 _DebugPrint($strKeyPath & "\" & $a_subkeys[$x]) _EnumKeys($strComputer, $s_hDefKey, $strKeyPath & "\" & $a_subkeys[$x]) $a_keys = _RegEnumValues($strComputer, $s_hDefKey, $strKeyPath & "\" & $a_subkeys[$x]) If Not @error Then For $y = 0 To UBound($a_keys) - 1 ConsoleWrite($a_keys[$y][0] & @TAB & ":" & @TAB & $a_keys[$y][1] & @TAB & ":" & @TAB & $a_keys[$y][2] & @LF) Next EndIf Next EndIf EndFunc ;==>_EnumKeys ;=============================================================================== ; ; Description: _RegEnumValues ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns a multi-dimensional array ([0] = key name, [1] = key value, [2] = key type) ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumValues(computer name, registry tree, sub key name) Enumerates the values of the given subkey ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumValues($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey, $x Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG = 0x80000005 If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $a_Type[12] = [11, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", "", "", "REG_MULTI_SZ","","","","undetermined"] Local $arrValueNames, $arrValueTypes Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumValues ($s_hDefKey, $strKeyPath, $arrValueNames, $arrValueTypes) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Local $a_ret[UBound($arrValueNames) ][3] For $x = 0 To UBound($arrValueNames) - 1 $a_ret[$x][0] = $arrValueNames[$x] $a_ret[$x][1] = RegRead($s_hDefKey & "\" & $strKeyPath, $arrValueNames[$x]) $a_ret[$x][2] = $a_Type[$arrValueTypes[$x]] Next Return $a_ret EndFunc ;==>_RegEnumValues ;=============================================================================== ; ; Description: _RegEnumKeys ; Parameter(s): computer name - string of remote computer or "." for current computer ; registry tree - contains the sSubKeyName path ; sub key name - A path that contains the named values to be enumerated ; Requirement: None ; Return Value(s): Returns An array of subkey strings ; If an error occurs @error is set and 0 is returned ; User CallTip: _RegEnumKeys(computer name, registry tree, sub key name) Enumerates the subkeys for a path ; Author(s): Gary Frost (custompcs at charter dot net) ; Note(s): A registry tree can be one of: ; "HKEY_LOCAL_MACHINE" ("HKLM") ; "HKEY_USERS" ("HKU") ; "HKEY_CURRENT_USER" ("HKCU") ; "HKEY_CLASSES_ROOT" ("HKCR") ; "HKEY_CURRENT_CONFIG" ("HKCC") ; ;=============================================================================== Func _RegEnumKeys($strComputer, $s_hDefKey, $strKeyPath) Local $hDefKey Enum $HKEY_CLASSES_ROOT = 0x80000000, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE, $HKEY_USERS, $HKEY_CURRENT_CONFIG = 0x80000005 If $strComputer = "." Then $strComputer = @ComputerName Switch StringUpper($s_hDefKey) Case "HKEY_LOCAL_MACHINE", "HKLM" $hDefKey = $HKEY_LOCAL_MACHINE Case "HKEY_USERS", "HKU" $hDefKey = $HKEY_USERS Case "HKEY_CURRENT_USER", "HKCU" $hDefKey = $HKEY_CURRENT_USER Case "HKEY_CLASSES_ROOT", "HKCR" $hDefKey = $HKEY_CLASSES_ROOT Case "HKEY_CURRENT_CONFIG", "HKCC" $hDefKey = $HKEY_CURRENT_CONFIG Case Else Return SetError(1, 1, 0) EndSwitch Local $arrValueNames Local $oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default:StdRegProv") $oReg.EnumKey ($s_hDefKey, $strKeyPath, $arrValueNames) If Not IsArray($arrValueNames) Then Return SetError(2, 2, 0) Return $arrValueNames EndFunc ;==>_RegEnumKeys Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "!===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "!===========================================================" & @LF) EndFunc ;==>_DebugPrint Edited June 8, 2007 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now