Writes a value to the registry.
RegWrite, ValueType, KeyName , ValueName, Value
Must be either REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, or REG_BINARY.
The full name of the registry key, e.g. HKLM\Software\SomeApplication
.
This must start with HKEY_LOCAL_MACHINE (or HKLM), HKEY_USERS (or HKU), HKEY_CURRENT_USER (or HKCU), HKEY_CLASSES_ROOT (or HKCR), or HKEY_CURRENT_CONFIG (or HKCC).
To access a remote registry, prepend the computer name and a colon (or in [v1.1.21+] a backslash), e.g. \\workstation01\HKLM
.
If blank or omitted, KeyName's default value will be used, which is the value displayed as "(Default)" by RegEdit. Otherwise, specify the name of the value that will be written to.
If blank or omitted, it defaults to an empty string or 0, depending on ValueType. Otherwise, specify the value to be written. 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.
Deprecated: This syntax is not recommended for use in new scripts. Use the new syntax described above instead.
RegWrite, ValueType, RootKey, SubKey , ValueName, Value
Must be either REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, or REG_BINARY.
Must be either HKEY_LOCAL_MACHINE (or HKLM), HKEY_USERS (or HKU), HKEY_CURRENT_USER (or HKCU), HKEY_CLASSES_ROOT (or HKCR), or HKEY_CURRENT_CONFIG (or HKCC).
To access a remote registry, prepend the computer name and a colon (or in [v1.1.21+] a backslash), e.g. \\workstation01\HKLM
.
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).
If blank or omitted, SubKey's default value will be used, which is the value displayed as "(Default)" by RegEdit. Otherwise, specify the name of the value that will be written to.
If blank or omitted, it defaults to an empty string or 0, depending on ValueType. Otherwise, specify the value to be written. 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.
[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.
If ValueType is REG_DWORD, Value should be between -2147483648 and 4294967295 (0xFFFFFFFF). In the registry, REG_DWORD values are always expressed as positive decimal numbers. To read it as a negative number with means such as RegRead, convert it to a signed 32-bit integer by using OutputVar := OutputVar << 32 >> 32
or similar.
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.
RegDelete, RegRead, registry loop, SetRegView, IniWrite
Despite the different syntax, both examples have the same effect: They write a string to the registry.
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE\SOFTWARE\TestKey, MyValueName, Test Value
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\TestKey, MyValueName, Test Value