Skip to Content
author's profile photo Former Member
Former Member

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

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)

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 11:46 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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. 😉

  • Posted on Jul 13, 2016 at 09:52 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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?

  • author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 01:14 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.