Create, open and close a registry entry.
hkey$ = CreateRegKey(key$[, subkey$])
hkey$ = OpenRegKey(key$[, subkey$])
r% = CloseRegKey(hkey$)
CloseRegKey hkey$
Before an application can add data to the registry, it must create or open a key. To create or open a key, an application always refers to the key as a subkey of a currently open key. A GFA-BASIC 32 application can use the OpenRegKey function to open a key and the CreateRegKey to create a key. The return value hkey$ contains the handle to the opened or created key\subkey and is used as the first parameter in GFA-BASIC's other low-level registry functions.
To close a key and write the data it contains into the registry you can use the GFA-BASIC 32 function CloseRegKey, which is also available as a command. CloseRegKey takes the return value of CreateRegKey or OpenRegKey.
The key$ must specify one of the following predefined reserved handle values (note three of them can be shortened):
"\\HKEY_CLASSES_ROOT" or "\\hkcr" or "\\80000000"
"\\HKEY_CURRENT_CONFIG"
"\\HKEY_CURRENT_USER" or "\\hkcu"
"\\HKEY_LOCAL_MACHINE" or "\\hklm"
"\\HKEY_USERS"
"\\HKEY_PERFORMANCE_DATA" (Windows NT)
"\\HKEY_DYN_DATA" (Windows 95 and Windows 98)
The key$ parameter can be assembled using "\\" & Hex(HKEY_CLASSES_ROOT)
The key$ may be concatenated with the subkey$.
The subkey$ parameter is optional (because it may be combined with key$) specifies the name of a key that is to be opened or created. This key must be a subkey of the key identified by the key$ parameter.
The return value is a key handle as a hexadecimal string preceded with \\, for instance "\\80000000".
PrintWrap = 1
Local hkey$, i%
Print "Installed software:"
hkey$ = OpenRegKey("\\HKEY_CURRENT_USER\Software")
For i% = 1 To GetRegSubKeyCount(hkey$)
Write GetRegSubKey(hkey$, i);
Print ", ";
Next
CloseRegKey hkey$
The GFA-BASIC 32 functions CreateRegKey, OpenRegKey, and CloseRegKey conform to the API functions RegCreateKey(),RegOpenKey(), and RegCloseKey(), respectively.
vbSaveSetting, vbDeleteSetting, vbGetSettingType, vbGetSetting, GetSetting, GetSettingType, SaveSetting, DeleteSetting, CreateRegKey, OpenRegKey, CloseRegKey, GetRegVal, GetRegValName, GetRegValType, GetRegValNameCount, GetRegSubKey, GetRegSubKeyCount
{Created by Sjouke Hamstra; Last updated: 27/09/2014 by James Gaite}