RegWrite()

Namespace ›› System ›› Mfunc ›› Methods ››
Parent Previous Next

RegWrite()

Mfunc.RegWrite(ValueType, RootKey, SubKey [, ValueName, Value])

Mfunc.RegWrite(ValueType, RootKey, SubKey [, ValueName, Value])

Writes a value to the registry.

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.

Throws

Throws MfException is non-zero then InnerException message is set to the value of A_LastError

Remarks

Wrapper for AutoHotkey Docs - RegWrite.
Static method.

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 AutoHotkey [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.

Any and/or all parameter for this function can be instance of MfString or var containing string.

See Also:AutoHotkey Docs - RegWrite.

Example

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