RegWrite

Writes a value to the registry.

RegWrite, ValueType, RootKey\SubKey [, ValueName, Value]  ; v1.1.21+
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).

RootKey\SubKey [v1.1.21+]

If RootKey is followed immediately by a slash (\), RootKey and SubKey are merged into a single parameter.

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.

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.

REG_BINARY and REG_MULTI_SZ values larger than 64K are supported in v1.1.10.01 and later. 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

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

; Alternative syntax (requires v1.1.21+):
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