#181207 - 2007-10-06 03:11 PM
Enumerating the Registry
|
Arkane
Getting the hang of it
Registered: 2004-08-14
Posts: 50
Loc: Bath, UK
|
I'm trying to write a script that will enumerate (and display) all keys, subkeys and values in the registry.
I've looked at EnumKey and EnumValue but I can't seem to enumerate ALL keys and subkeys, it seems to only enumerate keys up until it finds it can't enumerate anymore (HKCU\SomeKey\SomeKey1 etc..) but it doesn't go back to the next root-key (HKCU\SomeKey2, HKCU\SomeKey3 etc..).
Does anyone have any ideas why this might be?
The code I'm using is below :
Function EnumRegKeys($Key)
$SubKey = EnumKey($Key, $KIndex)
WHILE @ERROR = 0
$SaveKey = $Key
$Key = $Key + "\" + $SubKey
? "DEBUG-RK [" + $Key + "]"
EnumRegKeys($Key)
$Key = $SaveKey
IF @ERROR = 0
; try for next subkey
$KIndex = $KIndex + 1
$SubKey = EnumKey($Key, $KIndex)
ENDIF
LOOP
EndFunction
The $key value is currently HKEY_CURRENT_USER.
Any advice or assistance would be greatly appreciated.
Arkane
[changed quote to code - ntdoc]
|
|
Top
|
|
|
|
#181212 - 2007-10-06 05:00 PM
Re: Enumerating the Registry
[Re: Sealeopard]
|
Arkane
Getting the hang of it
Registered: 2004-08-14
Posts: 50
Loc: Bath, UK
|
Glen: I've looked at the DirList UDF - I still can't see what I'm doing wrong, it's probably something really simple that I'm missing.
If you take the script I wrote - run it against HKEY_CURRENT_USER you will see what I mean, it enumerates the subkeys but doesn't jump to the next root-key and I'm not sure how to make it do this.
Sealeopard: I appreciate that it may be extremely slow, is there a better way to do this? All I'd need is something that could perhaps enumerate all keys/values in a specified key (perhaps passed as an argument) and then it dumps it out to a text file (not a .reg file) and then I could get KiX to enumerate that instead.
The business case? Hard to say, more curiousity than a business case. I wanted to see how easy it would be (and how quick) to enumerate a registry hive with KIX and dump it out to a file. I'm wanting to compare 2 sets of registry information from different users - I've looked for free tools, most of them are GUI based and I'm looking for something small, quick and command-line based that would dump out the differences to a text file.
Arkane
|
|
Top
|
|
|
|
#181243 - 2007-10-07 09:56 AM
Re: Enumerating the Registry
[Re: NTDOC]
|
Arkane
Getting the hang of it
Registered: 2004-08-14
Posts: 50
Loc: Bath, UK
|
I've looked at both of those UDFs and saved them for greater study later on, but I've run them and they only seem to enumerate the first set of keys, they don't seem to go into subkeys, is this by design or is it really simple to make them do this?
|
|
Top
|
|
|
|
#181259 - 2007-10-07 11:01 PM
Re: Enumerating the Registry
[Re: Arkane]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I think you want to use a function that recurses itself. First time trying to write something like that. I hope it works as it should.
;************************************************************************* ; Script Name: EnumKeyAll ; Author: Wim Rotty ; Date: 7/10/2007 ; Description: Recursive function to list all subkeys ;************************************************************************* ;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare variables Dim $Key
;Initialize variables $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion";\Uninstall";\Installshield Uninstall Information"
;Code ??? For Each $RC in EnumKeyAll($Key) $RC ? Next Get $RC
;Personal UDF Section Function EnumKeyAll($Key) Dim $i, $strKey, $arrKeys[0] ReDim Preserve $EnumKeyAll[0] $i = 0 $strKey = EnumKey($Key,$i) While Not @ERROR $strKey = $Key+"\"+$strKey ;$strKey ? If Not $EnumKeyAll[0] = "" ReDim Preserve $EnumKeyAll[UBound($EnumKeyAll)+1] EndIf $EnumKeyAll[UBound($EnumKeyAll)] = $strKey $i = $i + 1 $strKey = EnumKey($Key,$i) Loop If Not $EnumKeyAll[0] = "" For Each $strKey in $EnumKeyAll ;$strKey ? $ArrKeys = EnumKeyAll($strKey) If Not $arrKeys[0] = "" For Each $strKey in $arrKeys ReDim Preserve $EnumKeyAll[UBound($EnumKeyAll)+1] $EnumKeyAll[UBound($EnumKeyAll)] = $strKey Next EndIf Next EndIf EndFunction
;UDF Section |
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 484 anonymous users online.
|
|
|