cancel
Showing results for 
Search instead for 
Did you mean: 

Can't use RegistryGet and RegistryKeys to access 64 bit registry

Former Member
0 Kudos

I'm using PB 12.5.2 and since it's a 32 bit application, I imagine I can't use RegistryKeys and RegistryGet to read the 64 bit registry -- as also noted in this thread...

RegistryGet return -1 ? | SCN

I'm trying to use RegOpenKeyEx as described in this article, but with KEY_WOW64_64KEY (256) as the samDesired parameter, and I can't seen to get it to work...

SAP Sybase Forums - PowerBuilder - General Discussion - How do I determine type of Registry value

Here MSDN says that the KEY_WOW64_64KEY flag needs to be combined using the OR operator with the other flags in this table that either query or access registry values. Is it possible to pass KEY_WOW64_64KEY | KEY_QUERY_VALUE (256 OR 1)?

Registry Key Security and Access Rights (Windows)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Steve,

Here is the code that works for me (to get the limit of handles) :

CONSTANT ulong ERROR_NONE = 0

CONSTANT ulong KEY_QUERY_VALUE = 1

CONSTANT ulong KEY_ALL_ACCESS = 63

CONSTANT ulong KEY_WOW64_64KEY = 256

CONSTANT ulong HKEY_CURRENT_USER = 2147483649

CONSTANT ulong HKEY_LOCAL_MACHINE = 2147483650

String ls_Key = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows", &

        ls_Value = "USERProcessHandleQuota"

uLong lul_Key, lul_Result, lul_Type, lul_Data = 4

Long ll_Handles

IF RegOpenKeyEx( HKEY_LOCAL_MACHINE, ls_Key, 0, KEY_QUERY_VALUE + KEY_WOW64_64KEY, lul_Key) = ERROR_NONE THEN

  lul_Result = RegQueryValueEx( lul_Key, ls_Value, 0, lul_Type, ll_Handles, lul_Data)

  RegCloseKey(lul_Key)

END IF

Regards,

Anthony

Former Member
0 Kudos

I'll try it Anthony -- thanks.

Former Member
0 Kudos

Regedit does show the key

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

But unfortunately that too returned an error 2 on RegOpenKeyEx.

Former Member
0 Kudos

And here is how my external functions are declared :

FUNCTION uLong RegOpenKeyEx(uLong hKey, Ref String lpSubKey, uLong ulOptions, uLong samDesired, Ref uLong phkResult) LIBRARY "advapi32.dll" ALIAS FOR "RegOpenKeyExW"

FUNCTION uLong RegCloseKey(uLong hKey) LIBRARY "advapi32.dll"

FUNCTION uLong RegQueryValueEx( &

  uLong hKey, String lpValueName, uLong lpReserved, &

  ref uLong lpType,ref Long lpData,ref uLong lpcbData &

  ) LIBRARY "advapi32.dll" ALIAS FOR "RegQueryValueExW"

Former Member
0 Kudos

Hi Steve;

   Have you tried the "RegOpenKeyExW" API Unicode variation?

Regards ... Chris

Former Member
0 Kudos

That did the trick. My function declarations were no good apparently. I was using ALIAS FOR "RegOpenKeyExA"

Former Member
0 Kudos

That was it Chris -- thanks.

Former Member
0 Kudos

Excellent news Steve! 

FWIW: I have been finding that many of the ANSI API's no longer work as we head towards newer Unicode versions of MS-Windows. Even in my frameworks, all the API's have been converted to "W" (wide) Unicode calls starting at least 5 years ago. 

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Steve;

  How about using PB 12.6 and build a 64bit EXE to read the 64bit registry values? If you don't want to upgrade your entire PB 12.5.x application to v12.6, you could just build a small EXE from PB 12.6 and call it from your v12.5.x application to return the proper registry values.

Food for thought (note - I have not tried this approach personally - just an idea).

Regards .. Chris

Former Member
0 Kudos

That's a workaround I could use I suppose. Thanks for the input Chris. Your help is always appreciated.

Former Member
0 Kudos

Hello Steve,

Just add them together...

256 = 0000000100000000

  1 = 0000000000000001

----------------------

257 = 0000000100000001


So, passing 257 to the API should do the trick.


If you are using the PFC, you could use n_cst_numerical.of_bitWiseOr(256, 1), but that is probably overkill.

Former Member
0 Kudos

Thanks for the reply Chris. I had tried that but it didn't work. I was still getting an error return code of 2 (ERROR_FILE_NOT_FOUND). Would adding them together equate to KEY_WOW64_64KEY AND KEY_QUERY_VALUE, instead of OR?