cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mrohit
Level 4

Different return values for RegDBKeyExist on 64-bit machines

Hi,

I am having issues with RegDBKeyExist function on a 64-bit OS.
I have the following scenario:
Installed a 32-bit application ABC on 64-bit machine. So the registry looks like
HKLM\SOFTWARE\Wow6432Node\ABC.

I want to check existence of ABC on 64-bit machine and i execute RegDBKeyExist (HKLM\SOFTWARE\Wow6432Node\ABC).

Prior to this i am also setting
REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;
RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );

On,
1. Windows Server SP2 machine it returns value < 0,
2. Windows Server 2008 R2 machine it returns 1.

Has anybody encountered similar kind of issue?
Is this due to the windows operating system or due to IS2010?

Any update/information would be helpful.

Thank You
Rohit
Labels (1)
0 Kudos
(1) Reply
joshstechnij
Level 10 Flexeran
Level 10 Flexeran

This is an issue with the registry support on the operating system. RegDBKeyExist calls the RegOpenKeyEx API and verifies the return value was ERROR_SUCCESS. If it was, 1 is returned by RegDBKeyExist, otherwise, -1 is returned.

Using the following code in a test C++ project:

HKEY hKey;
UINT uiRes;

uiRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Wow6432Node\\Test"), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);
printf("Opening Software\\Wow6432Node\\Test, WOW64_64KEY, result %d\n", uiRes);


yields the following output on a Windows 2008 machine even when the key exists:

Opening Software\Wow6432Node\Test, WOW64_64KEY, result 2


A result value of 2 is ERROR_FILE_NOT_FOUND, indicating the key was not found.

The same code returns 0 (ERROR_SUCCESS) on Windows 7 and 2008 R2, indicating a change in the operating system registry support.

Since this code is checking for a 32-bit key, it is recommended that 64-bit registry access not be enabled when checking for such a key.
0 Kudos