Reading values from the Registry
The registry is the new (tada) way of storing application-specific data on the user's system. Gone is the easy and understandable INI-system; from now on, it's as complex as ever. Anyway, here is some code to read values from the registry.
Author:


Global Const REG_BINARY As Long = 3
Global Const REG_DWORD As Long = 4
Global Const REG_SZ As Long = 1

Global Const HKEY_CLASSES_ROOT As Long = &H80000000

Global Const HKEY_CURRENT_CONFIG As Long = &H80000005

Global Const HKEY_CURRENT_USER As Long = &H80000001

Global Const HKEY_DYN_DATA As Long = &H80000006

Global Const HKEY_LOCAL_MACHINE As Long = &H80000002

Global Const HKEY_PERFORMANCE_DATA As Long = &H80000004

Global Const HKEY_USERS As Long = &H80000003


Dim Shared hKey As Long
Dim Shared SZ As Long
Dim Shared Success As Long



Function RegQuery(ByVal key As Long, ByVal subkey$, ByVal valuename$, lpdwType As Long) As Variant

'... Gets the Registry value from the key\subkey\value name.

  'key = Handle of a key.
  '...............HKEY_CLASSES_ROOT
  '...............HKEY_CURRENT_CONFIG
  '...............HKEY_CURRENT_USER
  '...............HKEY_DYN_DATA
  '...............HKEY_LOCAL_MACHINE
  '...............HKEY_PERFORMANCE_DATA
  '...............HKEY_USERS As Long
  'subkey$ = Address of subkey name.
  'valuename$ = Address of name of subkey to open.
  'lpdwType = Address of buffer for value type.
  '...............REG_BINARY  Binary value in any form
  '...............REG_DWORD   Double Word value
  '...............REG_SZ      String value
  
  Success = RegOpenKeyEx(key, subkey$, 0, KEY_ALL_ACCESS, hKey)
  If Success <> ERROR_SUCCESS Then GoTo Abort
  SZ = 256
  Select Case lpdwType
   Case REG_SZ
    v$ = String$(SZ, 0)
    Success = RegQueryValueEx(hKey, valuename$, 0, lpdwType, ByVal v$, SZ)
    If Success <> ERROR_SUCCESS Then GoTo Abort1
      RegQuery = Left$(v$, SZ)
   Case REG_BINARY, REG_DWORD
    Success = RegQueryValueEx(hKey, valuename$, 0&, lpdwType, nval&, SZ) 'SZ=4
    If Success <> ERROR_SUCCESS Then GoTo Abort1
      RegQuery = Hex(nval&)
  End Select
  Success = RegCloseKey(hKey)
  If Success <> ERROR_SUCCESS Then GoTo Abort2

  Exit Function

'...Display error message and return
Abort:
  Success = RegCloseKey(hKey)
  Bail_Out 1, key, subkey$, 0
  Exit Function
Abort1:
  Success = RegCloseKey(hKey)
  Bail_Out 4, key, subkey$, valuename$
  Exit Function
Abort2:
  Success = RegCloseKey(hKey)
  Bail_Out 7, key, subkey$, 0

End Function