Reference · reference
registry module (Windows)
use registry reads and writes the Windows registry. The module is registered on every platform, so a playbook compiles and validates identically everywhere; on Linux and macOS every call returns a runtime error. Guard a call with a step condition on os.family or with sys::family() from the sys module. Every function returns Result[…, string]. A key is a hive-prefixed path such as HKLM\Software\Vendor\App; the hive names are also available as the constants registry::HKLM, HKCU, HKCR, HKU and HKCC. A key or value counts as absent only when Windows reports it as not found (ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND). Any other failure, such as access denied, is an Err naming the key and the Win32 error, so read never returns None and key_exists never returns false for a key the process cannot open.
read
read
Reads a value. It returns None when the key or the value is absent. The Value is typed by the registry kind of the entry.
| Registry kind | Value |
|---|---|
| REG_SZ, REG_EXPAND_SZ | Value::String |
| REG_DWORD, REG_QWORD | Value::Int |
| REG_MULTI_SZ | Value::List of Value::String |
| REG_BINARY, REG_NONE | Value::List of Value::Int, one per byte (the fs::read_bytes shape) |
Any other registry type, such as REG_LINK, is an Err.
read_typed
read_typed
Reads a value together with its kind. It returns None when the key or the value is absent, and otherwise a map {kind, data}. kind is the name write accepts: sz, expand_sz, dword, qword, multi_sz, binary or none. data has the shape read returns. A registry type outside that list, such as REG_LINK or REG_RESOURCE_LIST, is not an Err here: the map is {kind: "other", type, data}, where type is the REG_* number as an int and data is the raw bytes as a list of ints. write does not accept other. Use read_typed when a REG_SZ must be told apart from a REG_EXPAND_SZ, or a REG_DWORD from a REG_QWORD. opts is the view map described under Registry views below; pass Value::Null for the native view.
write
write
Writes a value. kind selects the registry type and must match the shape of value: sz and expand_sz take a string, dword and qword take an int, multi_sz takes a list of strings, and binary and none take a list of byte ints from 0 to 255.
delete_value
delete_value
Deletes one value from a key.
create_key and delete_key
create_key
delete_key
create_key creates a key and any missing parents. delete_key deletes a key and its whole subtree.
key_exists
key_exists
Whether a key exists. It returns false only when the key is not found; any other failure is an Err.
value_names
value_names
Lists the names of a key's values. The list is sorted ignoring case, as the registry compares names, so it does not depend on the order Windows stores them in. The unnamed default value appears as "", the same name read and write use for it, and only when it is set; a key whose default value was never written does not list it. A key with no values returns an empty list. A missing key is an Err naming the key rather than an empty list, so a mistyped key cannot pass as a key with no values; check key_exists first when the key may legitimately be absent. Any other failure to open or enumerate the key is an Err naming the key and the Win32 error. opts is the view map described under Registry views below; pass Value::Null for the native view.
Registry views
read_with
write_with
delete_value_with
create_key_with
delete_key_with
key_exists_with
Each _with function behaves like the function without the suffix and takes a trailing opts map. The only option is view. "native" (the default) uses the process's own view. "wow64_32" forces the 32-bit view (WOW6432Node), and "wow64_64" forces the 64-bit view. read_typed and value_names take the same map. Pass Value::Null for the defaults. An unknown option or view is an Err. The functions without the suffix always use the native view.
use registry
use value
let key = "HKLM\\Software\\Vendor\\App"
match read? Some => if v.as_int == Some else ,
None => Ok,
}
}