RegWrite - Syntax & Usage | AutoHotkey

AutoHotkey

RegWrite

Writes a value to the registry.

New Syntax [v1.1.21+]

RegWrite, ValueType, KeyName , ValueName, Value

Parameters

ValueType

Must be either REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, or REG_BINARY.

KeyName

The full name of the registry key.

This must start with HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, or HKEY_CURRENT_CONFIG (or the abbreviations for each of these, such as HKLM). To access a remote registry, prepend the computer name and a colon (or [in v1.1.21+] a slash), as in this example: \\workstation01:HKEY_LOCAL_MACHINE

ValueName

The name of the value that will be written to. If blank or omitted, KeyName's default value will be used, which is the value displayed as "(Default)" by RegEdit.

Value

The value to be written. If omitted, it will default to an empty (blank) string, or 0, depending on ValueType. If the text is long, it can be broken up into several shorter lines by means of a continuation section, which might improve readability and maintainability.

Examples

RegWrite, REG_SZ, HKEY_LOCAL_MACHINE\SOFTWARE\TestKey, MyValueName, Test Value
RegWrite, REG_BINARY, HKEY_CURRENT_USER\Software\TEST_APP, TEST_NAME, 01A9FF77
RegWrite, REG_MULTI_SZ, HKEY_CURRENT_USER\Software\TEST_APP, TEST_NAME, Line1`nLine2

Old Syntax

Deprecated: This syntax is not recommended for use in new scripts. Use the new syntax instead.

RegWrite, ValueType, RootKey, SubKey , ValueName, Value

Parameters

ValueType

Must be either REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, or REG_BINARY.

RootKey

Must be either HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, or HKEY_CURRENT_CONFIG (or the abbreviations for each of these, such as HKLM). To access a remote registry, prepend the computer name and a colon (or [in v1.1.21+] a slash), as in this example: \\workstation01:HKEY_LOCAL_MACHINE

SubKey

The name of the subkey (e.g. Software\SomeApplication). If SubKey does not exist, it is created (along with its ancestors, if necessary). If SubKey is left blank, the value is written directly into RootKey (though some operating systems might refuse to write in HKEY_CURRENT_USER's top level).

ValueName

The name of the value that will be written to. If blank or omitted, SubKey's default value will be used, which is the value displayed as "(Default)" by RegEdit.

Value

The value to be written. If omitted, it will default to an empty (blank) string, or 0, depending on ValueType. If the text is long, it can be broken up into several shorter lines by means of a continuation section, which might improve readability and maintainability.

Examples

RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\TestKey, MyValueName, Test Value
RegWrite, REG_BINARY, HKEY_CURRENT_USER, Software\TEST_APP, TEST_NAME, 01A9FF77
RegWrite, REG_MULTI_SZ, HKEY_CURRENT_USER, Software\TEST_APP, TEST_NAME, Line1`nLine2

ErrorLevel

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

A_LastError is set to the result of the operating system's GetLastError() function.

Remarks

If ValueType is REG_DWORD, Value should be between -2147483648 and 4294967295 (0xFFFFFFFF).

When writing a REG_BINARY key, use a string of hex characters, e.g. the REG_BINARY value of 01,a9,ff,77 can be written by using the string 01A9FF77.

When writing a REG_MULTI_SZ key, you must separate each component from the next with a linefeed character (`n). The last component may optionally end with a linefeed as well. No blank components are allowed. In other words, do not specify two linefeeds in a row (`n`n) because that will result in a shorter-than-expected value being written to the registry.

[v1.1.10.01+]: REG_BINARY and REG_MULTI_SZ values larger than 64K are also supported. In older versions, they are truncated to 64K.

To retrieve and operate upon multiple registry keys or values, consider using a registry-loop.

For details about how to access the registry of a remote computer, see the remarks in registry-loop.

To read and write entries from the 64-bit sections of the registry in a 32-bit script or vice versa, use SetRegView.

Related

RegDelete, RegRead, Registry-loop, SetRegView, IniWrite