Windows Registry

The Registry object provides a simple API for interacting with the Windows Registry. It allows you to create, read, and delete keys and values.

Root Keys (HKEY)

Registry operations use the HKEY enumeration to specify the root key:

  • HKEY.ClassesRoot
  • HKEY.CurrentUser
  • HKEY.LocalMachine
  • HKEY.Users
  • HKEY.PerformanceData
  • HKEY.CurrentConfig
  • HKEY.DynData

Basic Operations

Creating and Deleting Keys

// Create a new key
Registry.CreateKey(HKEY.CurrentUser, '\Software\MyApp\Settings');

// Delete a key
Registry.DeleteKey(HKEY.CurrentUser, '\Software\MyApp\Settings');

Reading and Writing Values

Values can be strings, integers, or other basic types.

// Write a string value
Registry.WriteValue(HKEY.CurrentUser, '\Software\MyApp', 'Version', '1.0.0');

// Read a value with a default fallback
var ver := Registry.ReadValue(HKEY.CurrentUser, '\Software\MyApp', 'Version', '0.0.0');
PrintLn('Version: ' + ver);

// Write an integer
Registry.WriteValue(HKEY.CurrentUser, '\Software\MyApp', 'InstallCount', 1);
Result
Version: 1.0.0

Enumerating Keys and Values

// Get all subkey names
var subKeys := Registry.SubKeys(HKEY.CurrentUser, '\Software');

// Get all value names in a key
var valNames := Registry.ValueNames(HKEY.CurrentUser, '\Software\MyApp');

Permissions

Modifying the registry typically requires appropriate user permissions. For example, writing to HKEY.LocalMachine usually requires administrative privileges.

On this page