Hi.

While implementing a script for remote network adapter check purposes I stumbled over a misbehaviour which looks like a bug in EnumKey() to me.
To be concise: EnumKey() DOES enumerate all keys beneath a given key for the registry on the LOCAL machine. It DOES NOT enumerate all keys beneath a given key for the registry on a REMOTE machine. Can be reproduced using KIX 4.50, 4.51, 4.52 and with different local/remote computer combinations available at my site.

The actual code and behaviour (warning: talkative text ahead):

Currently the script emumerates all NICs in the registry of the local or a remote machine and prints them to the console. When I enumerate the NICs (available as distinct registry keys beneath HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards) locally everything works fine. When I enumerate NICs from a remote machine, only one NIC (only one registry key) shows up.

OK. Execute the script locally on a machine named FOO_MACHINE:

-- snip ---

; Here we are
C:\>echo %COMPUTERNAME%
FOO_MACHINE

; Enumerate local registry keys
C:\>C:\KIX32_452.EXE C:\QueryNIC.kix

Delivered Subkey: 8
Delivered Subkey: 9
Delivered Subkey:
-- Adapter ---
HP NC7782 Gigabit Server Adapter
{AF6F0242-0F79-4199-94BC-DFD56B323EBB}
-- Adapter ---
HP NC7782 Gigabit Server Adapter
{FC3E6B8A-00E7-4619-B633-6348CAD01143}

C:\>

-- snap ---

Fine, two NICs found. Thats right. Now move to a different machine (named BAR_MACHINE) execute the script there and aim at our previous, the target machine named FOO_MACHINE:

-- snip ---

; Here we are
C:\>echo %COMPUTERNAME%
BAR_MACHINE

; Now enumerate remote registry keys
C:\>C:\KIX32_452.EXE C:\QueryNIC.kix $MACHINENAME=FOO_MACHINE

Delivered Subkey: 9
Delivered Subkey:
-- Adapter ---
HP NC7782 Gigabit Server Adapter
{FC3E6B8A-00E7-4619-B633-6348CAD01143}

C:\>

-- snap ---

Huh ? Something wrong. Are the keys visible and accessible from here ? Lets verify using REG.EXE

-- snip ---

; Here we are
C:\>echo %COMPUTERNAME%
BAR_MACHINE

; Query the remote registry
C:\>reg query "\\FOO_MACHINE\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" /s

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\8
ServiceName REG_SZ {AF6F0242-0F79-4199-94BC-DFD56B323EBB}
Description REG_SZ HP NC7782 Gigabit Server Adapter

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\9
ServiceName REG_SZ {FC3E6B8A-00E7-4619-B633-6348CAD01143}
Description REG_SZ HP NC7782 Gigabit Server Adapter

C:\>

-- snap ---

All requested keys are there and can be seen from remote. And finally the script 'QueryNIC.kix' that fails to work properly. Definitly too bulky as a simple prove code, but 100% real life script. The significant line ist the only EnumKey()line.

-- snip ---

GLOBAL $NULLSTRING
GLOBAL $NONE
$NULLSTRING = ''
$NONE = 0

if isdeclared( $MACHINENAME )
if len( $MACHINENAME ) > 0
$MACHINENAME = lcase( $MACHINENAME )
else
$MACHINENAME = lcase( @wksta )
endif
else
GLOBAL $MACHINENAME
$MACHINENAME = lcase( @wksta )
endif

GLOBAL $ADAPTER[ 99 , 1 ] ; 100 Zeilen (0..99), 2 Spalten (0..1)
GLOBAL $ANZAHL_ADAPTER
GLOBAL $SP_NAME
GLOBAL $SP_DESCR
$ANZAHL_ADAPTER = 0
$SP_DESCR = 0
$SP_NAME = 1

GLOBAL $ADAPTER_REGPATH
$ADAPTER_REGPATH = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards'

dim $current_subkey
dim $index_adapter
$current_subkey = $NULLSTRING
$index_adapter = 0

do

$current_subkey = enumkey( $ADAPTER_REGPATH , $index_adapter )

; Print for debugging only, reveals failure of 'enumkey' for remote machines
? 'Delivered Subkey: $current_subkey'

if @error = $NONE

$temp = '\\' + $MACHINENAME + '\' + $ADAPTER_REGPATH + '\' + $current_subkey

$ADAPTER[ $index_adapter , $SP_DESCR ] = readvalue( $temp , 'Description' )
$ADAPTER[ $index_adapter , $SP_NAME ] = readvalue( $temp , 'ServiceName' )

$index_adapter = $index_adapter + 1

endif

until @error <> $NONE

$ANZAHL_ADAPTER = $index_adapter

; Some more code to be added in the future here ... for now just print results:

$index_adapter = 0

do

? '-- Adapter ---'
? $ADAPTER[ $index_adapter , $SP_DESCR ]
? $ADAPTER[ $index_adapter , $SP_NAME ]

$index_adapter = $index_adapter + 1

until $ANZAHL_ADAPTER = $index_adapter

-- snap ---