;Author: Richard von Mallesch (It took my meds)
;
;Contributors: BoForce
;
;Action: Allows you to list the names of the subkeys contained in a registry key Or subkey.
;
;Version: 1.0
;
;Date: 2009-09-24
;
;Dependencies:
; SteelKix version: 0.2
; Tested with Dot Net 3.5
;
;Syntax: EnumKey ("subkey", index)
;
;Parameters:
;Subkey
; Specifies the key or subkey For which you want to enumerate the subkeys.
;Index
; A numeric value representing the position of the subkey whose name you want to discover. Zero (0) represents the first subkey in the key.
;Returns: 0 Function returns a string representing the subkey in the specified key
; 259 Subkey does Not Exist
; Error code Function failed.
;See Also: EnumValue( )
;Example:
;
; $Index = 0
; $KeyName = EnumKey("HKEY_CURRENT_USER\Console\", $Index)
; While $KeyName
; ? "Name found: $KeyName"
; $Index = $Index + 1
; $KeyName = EnumKey("HKEY_CURRENT_USER\Console\", $Index)
; Loop
Function EnumKey($Key, $Index)
Dim $Win32, $rtHive, $rtKey, $rk, $aKeys
Imports $Win32 = Microsoft.Win32
$rtHive = $Key.ToString.Split("\".ToCharArray())[0]
$Key = $Key.Remove($rtHive+'\',$rtHive.Length+1)
Select
Case $rtHive = 'HKEY_CLASSES_ROOT' Or $rtHive = 'HKCR'
$rtHive = $Win32.Registry.ClassesRoot
Case $rtHive = 'HKEY_CURRENT_USER' Or $rtHive = 'HKCU'
$rtHive = $Win32.Registry.CurrentUser
Case $rtHive = 'HKEY_LOCAL_MACHINE' Or $rtHive = 'HKLM'
$rtHive = $Win32.Registry.LocalMachine
Case $rtHive = 'HKEY_USERS' Or $rtHive = 'HKU'
$rtHive = $Win32.Registry.Users
EndSelect
$rk = $rtHive.OpenSubKey($Key)
$aKeys = $rk.GetSubKeyNames
If $aKeys.Length > $Index
$EnumKey = $aKeys[$Index]
Exit 0
Else
Exit 256
EndIf
EndFunction