Results 1 to 3 of 3

Thread: DF 19.1 cRegistry HKEY_LOCAL_MACHINE bug?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Goteborg, Sweden
    Posts
    3,189

    Default DF 19.1 cRegistry HKEY_LOCAL_MACHINE bug?

    Windows 10 x64 machines (tested on two different machines)

    This may have been reported/discussed before but I couldn't find it.

    I needed a function that derives the installation path (bin folder) for AutoCAD from Windows registry.

    To get the install path is a bit cumbersome because one has to start in HKEY_CURRENT_USER and look up some values, to later continue in HKEY_LOCAL_MACHINE.

    And it was when using KeyExists and OpenKey in the HKEY_LOCAL_MACHINE branch I run into trouble, as both of those functions always returned False although the registry keys clearly existed and the pfAccessRights had been set to KEY_READ.

    Note that if the keys to search for is under the Wow6432Node it works just fine. But otherwise it does not. And the problem is that the pfAccessRights = KEY_READ is not enough under HKEY_LOCAL_MACHINE!

    After some reading of Microsoft documentation I found and declared:
    Define KEY_WOW64_64KEY for |CI$0100

    For the function below, this is the Registry branch to search for AutoCAD:

    HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R23.1 \ACAD-3001:409

    and the string value that holds the installaltion path is: AboutDirective

    Thus the following function that uses a combination of KEY_READ ior KEY_WOW64_64KEY works. But try to remove the KEY_WOW64_64KEY and you will see it fail.

    Code:
    // Returns the install path for the AutoCAD program.
    // The returned path will _not_ contain any trailing "\" character.
    // Note: The path often contains spaces (" "), so make sure to surround
    // expressions with the returned string with an extra pair of quotes ("").
    Function AutoCADInstallPath Global Returns String
        String sInstallPath sKey sValue sVersion1 sVersion2
        Boolean bExists bOpened bX64
        Handle hoRegistry
        
        Move "" to sInstallPath
        Get Create (RefClass(cRegistry)) to hoRegistry  
        Set phRootKey of hoRegistry to HKEY_CURRENT_USER
        Set pfAccessRights of hoRegistry to KEY_READ
        Move "Software\Autodesk\AutoCAD" to sKey
    
    
        Get KeyExists of hoRegistry sKey to bExists
        If bExists Begin
            Get OpenKey of hoRegistry sKey to bOpened
            If (bOpened = True) Begin
                Get ReadString of hoRegistry "CurVer" to sVersion1
            End
            Else Begin
                Send Destroy of hoRegistry
                Function_Return ""
            End
            Send CloseKey of hoRegistry
            Move (sKey + "\" + sVersion1) to sKey
            Get OpenKey of hoRegistry sKey to bOpened
            If (bOpened = True) Begin        
                Move "CurVer" to sValue
                Get ValueExists of hoRegistry sValue to bExists
                If (bExists = True) Begin
                    Get ReadString of hoRegistry sValue to sVersion2
                    Move (sKey + "\" + sVersion2) to sKey
                End
            End                   
            Else Begin
                Send Destroy of hoRegistry
                Function_Return ""
            End
            Send CloseKey of hoRegistry
            
            Set phRootKey of hoRegistry to HKEY_LOCAL_MACHINE 
            // Note: It is absolutely crucial to use: (KEY_READ ior KEY_WOW64_64KEY),
            // else every KeyExists and OpenKey will return False (!).
            Set pfAccessRights of hoRegistry to (KEY_READ ior KEY_WOW64_64KEY)
    
    
            Get KeyExists of hoRegistry sKey to bExists
            If (bExists = True) Begin
                Get OpenKey of hoRegistry sKey to bOpened
                If (bOpened = True) Begin        
                    Move "AcadLocation" to sValue
                    Get ValueExists of hoRegistry sValue to bExists
                    If (bExists = True) Begin
                        Get ReadString of hoRegistry sValue to sInstallPath
                    End
                End                   
            End
            Else Begin
                Send Destroy of hoRegistry
                Function_Return ""
            End
                
        End
    
        Send Destroy of hoRegistry
        If (Right(sInstallPath, 1) = "\") Begin
            Move (Left(sInstallPath, Length(sInstallPath) - 1)) to sInstallPath
        End
        
        Function_Return sInstallPath
    End_Function
    Hope this will help somebody else tripping over the same problem.
    Last edited by Nils G. Svedmyr; 18-May-2020 at 01:15 PM. Reason: Added info about the OS type
    Nils Svedmyr
    RDC Tools International
    www.rdctools.com

    "The problem with internet quotes is that you don't know if they are true."
    Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •