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 :

 Code:
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]