# RegWrite

Writes a value to the registry.

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, 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.

#### ErrorLevel

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

#### Remarks

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

Although no more than 64 KB of data can be written to REG_BINARY and REG_MULTI_SZ values, the other types are unlimited except under Windows 95/98/ME, which have a 64 KB limit for all types. If the 64 KB limit applies, data beyond that limit will not be written. In other words, only the first 64 KB of a very large string will be saved to the registry.

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. Note: Windows 95 does not support the REG_MULTI_SZ value type.

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, see www.autohotkey.com/forum/topic39560.html

#### Related

RegDelete, RegRead, Registry-loop, 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