How To: Use Avenue to get values from the Windows registry


The instructions provided are for accessing values in your Windows registry, whereby Avenue sends commands to the advapi32.dll. The example used below retrieves ArcView's installation directory from the Windows registry. Modify this code as needed to access other registry values.


The instructions below include making changes to essential parts of your operating system. It is recommended that you backup your operating system and files, including the registry, before proceeding. Consult with a qualified computer systems professional, if necessary.

Esri cannot guarantee results from incorrect modifications while following these instructions; therefore, use caution and proceed at your own risk.
  1. Open a new script window.
    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.
  2. Copy the code into the new script window:
    'This script reads the PATH key (installation directory) for ArcView from 
    'the system registry. Modify it to read any value 
    'from the registry
    'for more information on defining constants, search the web for 'Registry API constants'
    'Define some constants 
    'Constants for the main registry entries 
    HKEY_CLASSES_ROOT = 2147483648 
    HKEY_CURRENT_USER = 2147483649 
    HKEY_LOCAL_MACHINE = 2147483650 
    HKEY_USERS = 2147483651 
    HKEY_CURRENT_CONFIG = 2147483653 
    HKEY_DYN_DATA = 2147483654 
    lKeyHandle = 0 
    sResult = String.MakeBuffer(255) 
    REG_SZ = 1 
    'Make sure the path is correct, and make a DLL object 
    ' For Windows 95/98/ME/2000/XP use c:\windows\system\advapi32.dll 
    ' For Windows NT use c:\winnt\system32\advapi32.dll 
    advapi32DLL = DLL.Make("c:\winnt\system32\advapi32.dll".asFileName) 
    if (advapi32DLL = nil) then 
    'Create a DLL procedure object for opening a registry key 
    procOpenKey = DLLPROC.Make( advapi32DLL, "RegOpenKeyExA", #DLLPROC_TYPE_INT32, 
    if (procOpenKey = nil) then 
    'Make the call, change the first and second arguments to open a different 
    'registry key 
    x = procOpenKey.Call({HKEY_LOCAL_MACHINE, "SOFTWARE\ESRI\ArcView GIS Version 3.0\CurrentVersion", 0, KEY_QUERY_VALUE, lKeyHandle})
    'If x is zero, call was successful 
    'Create a DLL procedure object for reading the opened registry key 
    procQueryKey = DLLPROC.Make( advapi32DLL, "RegQueryValueExA", 
    'Make the call. Change the second argument to read a different key 
    x = procQueryKey.Call({lKeyHandle, "Path", 0, REG_SZ, sResult, 255}) 
    'Display the result 
    MsgBox.Info(sResult.AsString,"And the answer is ...") 
    Depending on your operating system you may need to change the path to the advapi32.dll file. See the comments with in the code.
  3. Click the Compile button.
    [O-Image] Script compile button
  4. Click the Run button.
    [O-Image] Run compiled script button

Related Information