win32reg(3)
β¨ NAME β¨
okay so, welcome to the win32reg manual page π (this one lives in the Erlang Module Definition manual, just so u know where u are)
win32reg β bestie, it gives u access to the registry on Windows πͺβ¨
π DESCRIPTION π
So basically, this module gives u read and write access to the registry on Windows. Under the hood it's essentially a port driver wrapped around the Win32 API calls for accessing the registry. no cap π«Ά
The registry is a hierarchical database, used to store all sorts of system and software information in Windows. It's got installation data in it, and installers and system programs keep updating it. The Erlang installer updates the registry too, by adding the data that Erlang needs. slay π
The registry contains keys and values, and the vibe is very file-system-coded:
- Keys are like the directories in a file system β they form a hierarchy.
- Values are like files β they have a name and a value, and also a type. π¦
Paths to keys go left to right, with subkeys to the right and a backslash between keys. (And bestie, remember: backslashes must be doubled in Erlang strings, iykyk.) Case is preserved but not significant. periodt.
For example, "\\hkey_local_machine\\software\\Ericsson\\Erlang\\5.0" is the key for the installation data for the latest Erlang release. iconic.
There are six entry points in the Windows registry, top-level keys. They can be abbreviated in this module as follows π
hkcrβHKEY_CLASSES_ROOTcurrent_userβHKEY_CURRENT_USERhkcuβHKEY_CURRENT_USERlocal_machineβHKEY_LOCAL_MACHINEhklmβHKEY_LOCAL_MACHINEusersβHKEY_USERShkuβHKEY_USERScurrent_configβHKEY_CURRENT_CONFIGhkccβHKEY_CURRENT_CONFIGdyn_dataβHKEY_DYN_DATAhkddβHKEY_DYN_DATA
So the key above can be written as "\\hklm\\software\\ericsson\\erlang\\5.0" β¨
This module uses a current key. It works much like the current directory. From the current key, values can be fetched, subkeys can be listed, and so on. main character energy fr fr π
Under a key, any number of named values can be stored. They have names, types, and data.
win32reg supports storing of the following types:
REG_DWORD, which is an integerREG_SZ, which is a stringREG_BINARY, which is a binary πΈ
Other types can be read, and are returned as binaries. π
There is also a "default" value, which has the empty string as name. It is read and written with the atom default instead of the name. cute.
Some registry values are stored as strings with references to environment variables, for example, %SystemRoot%Windows. SystemRoot is an environment variable, and is to be replaced with its value. Function expand/1 is provided so that environment variables surrounded by % can be expanded to their values. π§
For more information on the Windows registry, see consult the Win32 Programmer's Reference. π
π See Also π
erl_posix_msg, The Windows 95 Registry (book from O'Reilly), Win32 Programmer's Reference (from Microsoft)
π DATA TYPES π
name() :: string() | default.
yep, that's the one π
-opaque reg_handle()
As returned by open/1. don't be peeking inside, it's opaque for a reason bestie π
value() :: string() | integer() | binary().
π₯ FUNCTIONS π₯
change_key/2
change_key(RegHandle, Key) -> ReturnValue
when
RegHandle :: reg_handle(),
Key :: string(),
ReturnValue :: ok | {error, ErrorId :: atom()}.
Changes the current key to another key. Works like cd. The key can be specified as a relative path or as an absolute path, starting with \. π¦
change_key_create/2
change_key_create(RegHandle, Key) -> ReturnValue
when
RegHandle :: reg_handle(),
Key :: string(),
ReturnValue :: ok | {error, ErrorId :: atom()}.
Creates a key, or just changes to it, if it is already there. Works like a combination of mkdir and cd. Calls the Win32 API function RegCreateKeyEx(). β¨
The registry must have been opened in write mode, bestie. don't forget π
close/1
close(RegHandle) -> ok
when
RegHandle :: reg_handle().
Closes the registry. After that, the RegHandle cannot be used. it's giving expired π
current_key/1
current_key(RegHandle) -> ReturnValue
when
RegHandle :: reg_handle(),
ReturnValue :: {ok, string()}.
Returns the path to the current key. This is the equivalent of pwd. π
Notice that the current key is stored in the driver, and can be invalid (for example, if the key has been removed). ngl, watch out for that.
delete_key/1
delete_key(RegHandle) -> ReturnValue
when
RegHandle :: reg_handle(),
ReturnValue :: ok | {error, ErrorId :: atom()}.
Deletes the current key, if it is valid. Calls the Win32 API function RegDeleteKey(). Notice that this call does not change the current key (unlike change_key_create/2). This means that after the call, the current key is invalid. π
delete_value/2
delete_value(RegHandle, Name) -> ReturnValue
when
RegHandle :: reg_handle(),
Name :: name(),
ReturnValue :: ok | {error, ErrorId :: atom()}.
Deletes a named value on the current key. The atom default is used for the default value. π
The registry must have been opened in write mode.
expand/1
expand(String) -> ExpandedString
when
String :: string(),
ExpandedString :: string().
Expands a string containing environment variables between percent characters. Anything between two % is taken for an environment variable, and is replaced by the value. Two consecutive % are replaced by one %. π«
A variable name that is not in the environment results in an error. sorry bestie π
format_error/1
format_error(ErrorId) -> ErrorString
when
ErrorId :: atom(),
ErrorString :: string().
Converts a POSIX error code to a string (by calling file:format_error/1). easy πΈ
open/1
open(OpenModeList) -> ReturnValue
when
OpenModeList :: [OpenMode],
OpenMode :: read | write,
ReturnValue :: {ok, RegHandle} | {error, ErrorId :: enotsup},
RegHandle :: reg_handle().
Opens the registry for reading or writing. The current key is the root (HKEY_CLASSES_ROOT). Flag read in the mode list can be omitted. β¨
Use change_key/2 with an absolute path after open. iykyk π
set_value/3
set_value(RegHandle, Name, Value) -> ReturnValue
when
RegHandle :: reg_handle(),
Name :: name(),
Value :: value(),
ReturnValue :: ok | {error, ErrorId :: atom()}.
Sets the named (or default) value to value. Calls the Win32 API function RegSetValueEx(). The value can be of three types, and the corresponding registry type is used. The supported types are the following:
REG_DWORDfor integersREG_SZfor stringsREG_BINARYfor binaries π₯
Other types cannot be added or changed. nope, not happening π
The registry must have been opened in write mode.
sub_keys/1
sub_keys(RegHandle) -> ReturnValue
when
RegHandle :: reg_handle(),
ReturnValue :: {ok, [SubKey]} | {error, ErrorId :: atom()},
SubKey :: string().
Returns a list of subkeys to the current key. Calls the Win32 API function EnumRegKeysEx(). π
Avoid calling this on the root keys, as it can be slow. like, painfully slow bestie π
value/2
value(RegHandle, Name) -> ReturnValue
when
RegHandle :: reg_handle(),
Name :: name(),
ReturnValue :: {ok, Value :: value()} | {error, ErrorId :: atom()}.
Retrieves the named value (or default) on the current key. Registry values of type REG_SZ are returned as strings. Type REG_DWORD values are returned as integers. All other types are returned as binaries. π
values/1
values(RegHandle) -> ReturnValue
when
RegHandle :: reg_handle(),
ReturnValue :: {ok, [ValuePair]} | {error, ErrorId :: atom()},
ValuePair :: {Name :: name(), Value :: value()}.
Retrieves a list of all values on the current key. The values have types corresponding to the registry types, see value/2. Calls the Win32 API function EnumRegValuesEx(). π
okay that's the whole page bestie, u ate that π«Ά this lil manual came to u courtesy of Ericsson AB, riding with stdlib 8.0.4, and it's stamped win32reg(3) β catch u in the registry, mwah πβ¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms