sys.registry.write(root, key, value, data, [isexpanded])
Write a value under the specified key in the Windows registry.
Parameters
rootkey
Indicates the predefined entry point in the Windows registry, from which the key/value will be accessed. Must be one of the following string :
- "HKEY_CLASSES_ROOT" : types (or classes) of documents and the properties associated with those types
- "HKEY_CURRENT_CONFIG" : information about the current hardware
- "HKEY_CURRENT_USER" : preferences of the current user
- "HKEY_LOCAL_MACHINE" : data about the computer, system memory, and installed hardware and software
key
Indicates the name of the key under which the value will be written.
value
Indicates the name of the value.
data
Indicates the content of the value according to the following conversion rules :
Lua value type | Registry value type |
---|---|
Buffer |
REG_BINARY |
number |
REG_QWORD REG_DWORD |
string |
REG_SZ REG_EXPAND_SZ |
table of strings |
REG_MULTI_SZ |
|
REG_NONE |
[isexpanded]
Indicates if the environment variables should be expanded (for strings only), defaults to false
Return value
This function returnstrue
if the value has been written to the registry, or otherwise false
(See sys.error to get the error message).
Example
-- Get the current user PATH environment variable
local user_path = sys.registry.read("HKEY_CURRENT_USER", "Environment", "Path", false) or ""
-- Append it with a new folder "D:\\mypath\\bin\\"
sys.registry.write("HKEY_CURRENT_USER", "Environment", "Path", user_path..";".."D:\\mypath\\bin\\", true)