Archive: EnumRegKey - infinite loop on some Win98 machine, but not others?


EnumRegKey - infinite loop on some Win98 machine, but not others?
I need to enumerate Outlook profiles on Windows 98 machines as part of my NSIS script. I have 42 machines as an initial group I'm working with, and of the 42, I had 6 that went into an infinite loop when trying to enumerate "HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles". I can't see anything different on these machines, they all have anywhere from 1 to 7-8 Outlook profiles configured. I'm doing some testing on one of the machines and can't determine why this loops endlessly:

Machine has only one Outlook profile, "GTriplett", so beneath Profiles in the registry, that is the only key present, and should therefore be the only key EnumRegKey sees before it returns an empty string or errors out. I've added some debugging stuff (well, attempt at debugging) to the loop so I can see the condition of variables and whatnot via DetailPrint, but I'm stumped.

The NSIS loop is (debugging stuff is still in it):

--------------------------------
; First build a stack of Outlook profiles
StrCpy $1 0
StrCpy $2 0
DetailPrint "Building a list of Outlook profiles..."
loop_getprofs:
ClearErrors
DetailPrint "Var 1 is $1, now reading registry"
EnumRegKey $1 HKCU "Software\Microsoft\Windows Messaging Subsystem\Profiles" $2
IfErrors getprof_error
StrCmp $1 "" done_getprofs
Push $1
DetailPrint " $2. $1"
IntOp $2 $2 + 1
StrCpy $1 0
StrCmp $2 30 EndIt
Goto loop_getprofs

getprof_error:
DetailPrint "Ran into an error reading HKCU\Sofware\MS\WMS\Profiles at index $2"
done_getprofs:
-----------------------------------


The Details window of NSIS shows this:

----------------------------------------
Building a list of Outlook profiles...
Var 1 is 0, now reading registry
0. GTriplett
Var 1 is 0, now reading registry
1. GTriplett
Var 1 is 0, now reading registry
2. GTriplett
Var 1 is 0, now reading registry
3. GTriplett
--- snip ---
Var 1 is 0, now reading registry
28. GTriplett
Var 1 is 0, now reading registry
29. GTriplett
Completed
------------------------------------

So you can see that $2 is incrementing, and therefore EnumRegKey is being told to read an incrementing index, yet it always returns "GTriplett", and will loop infinitely on it. The majority of my machines went just fine, is this a bug in EnumRegKey, or registry corruption, or... any other ideas?

Thanks very much,
Mark


update
As an update, it appears that on the Windows 98 machines where I saw an issue, that I can enumerate *any* registry key and get an infinite loop. I am very definitely incrementing the key index with IntOp, and echoing the registry key name, and can see that the script goes through the values as you would expect, listing each one individually. When it exhausts the keys, though, it just keeps listing the last key it hit, over and over, and the key index just keeps climbing from the IntOp (the line in my script snippet above, "DetailPrint $2. $1" is showing me the key index and the result of that particular enumeration).

Has anyone else run into something like this? Is there some update to Windows that these machines have missed, and they have a broken API "RegEnumKey" function?


Run the attached executable on a machine which shows this behavior and let me know what is the result you get from it. It will call RegEnumKey with an index above the number of available subkeys and show the result.