> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebind.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# rb.registry

> Read, write and delete Windows registry keys and values.

`rb.registry` reads and writes the Windows registry. A script reaches for it to
keep a value where other programs can find it, or to change a setting an app
reads from the registry. No [permission](https://docs.rebind.gg/reference/sdk/modeline.md#permissions)
guards it.

**Needs:** Windows.

This script counts its own launches in a value under `HKCU`:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0 platforms=windows
local key = [[HKCU\Software\RebindExample]]

-- read raises when the key or value does not exist yet
local ok, count = pcall(rb.registry.read, key, "LaunchCount")
if not ok then
  count = 0
end

rb.registry.write(key, "REG_DWORD", "LaunchCount", count + 1)
rb.registry.write(key, "REG_SZ", "LastScript", "example")
print("launches:", rb.registry.read(key, "LaunchCount"))
```

| Signature | Effect |
| - | - |
| `rb.registry.read(key_path: string, value_name: string) -> string \| number` | a number for `REG_DWORD` and `REG_QWORD`, a string for `REG_SZ` and `REG_EXPAND_SZ`; other types raise |
| `rb.registry.write(key_path: string, type: string, value_name: string, value: any) -> ()` | creates the key when needed |
| `rb.registry.delete_value(key_path: string, value_name: string) -> ()` | |
| `rb.registry.delete_key(key_path: string) -> ()` | removes the key and its subkeys |
| `rb.registry.create_key(key_path: string) -> ()` | |

On other systems every call raises `Registry is only available on Windows`.

`key_path` starts with a hive: `HKLM`, `HKCU`, `HKCR`, `HKU`, `HKCC` or their
`HKEY_` forms. `type` is `REG_SZ`, `REG_EXPAND_SZ`, `REG_MULTI_SZ` (a list of
strings), `REG_DWORD`, `REG_QWORD` (numbers) or `REG_BINARY` (a byte string).
`write` accepts every type listed, but `read` cannot return `REG_MULTI_SZ` or
`REG_BINARY` values.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.