HOW TO
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.
Warning: 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.
Code: '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 KEY_QUERY_VALUE = 1 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 exit end 'Create a DLL procedure object for opening a registry key procOpenKey = DLLPROC.Make( advapi32DLL, "RegOpenKeyExA", #DLLPROC_TYPE_INT32, {#DLLPROC_TYPE_INT32, #DLLPROC_TYPE_STR, #DLLPROC_TYPE_INT32, #DLLPROC_TYPE_INT32, #DLLPROC_TYPE_PINT32}) if (procOpenKey = nil) then exit end '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", #DLLPROC_TYPE_INT32, {#DLLPROC_TYPE_INT32, #DLLPROC_TYPE_STR, #DLLPROC_TYPE_INT32, #DLLPROC_TYPE_PINT32, #DLLPROC_TYPE_STR, #DLLPROC_TYPE_PINT32}) '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 ...")
Note: Depending on your operating system you may need to change the path to the advapi32.dll file. See the comments with in the code.
Get help from ArcGIS experts
Download the Esri Support App