Creates a key or value in the registry.
RegWrite ( "keyname" [, "valuename", "type", value] )
keyname | The registry key to write to. If no other parameters are specified this key will simply be created. |
valuename | [optional] The valuename to write to. |
type | [optional] Type of key to write: "REG_SZ", "REG_MULTI_SZ", "REG_EXPAND_SZ", "REG_DWORD", "REG_QWORD", or "REG_BINARY". |
value | [optional] The value to write. |
Success: | 1. |
Failure: | 0 and sets the @error flag to non-zero if error writing registry key or value. |
@error: | 1 = unable to open requested key 2 = unable to open requested main key 3 = unable to remote connect to the registry -1 = unable to open requested value -2 = value type not supported |
A registry key must start with "HKEY_LOCAL_MACHINE" ("HKLM") or "HKEY_USERS" ("HKU") or "HKEY_CURRENT_USER" ("HKCU") or "HKEY_CLASSES_ROOT" ("HKCR") or "HKEY_CURRENT_CONFIG" ("HKCC").
When running on 64-bit Windows if you want to write a key or value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64.
AutoIt supports registry keys of type REG_BINARY, REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ, REG_QWORD, and REG_DWORD.
To access the (Default) value use "" (an empty string) for the valuename.
When writing a REG_MULTI_SZ key you must separate each value with @LF. The value must NOT end with @LF unless you want an empty substring (see example).
It is possible to access remote registries by using a keyname in the form "\\computername\keyname". To use this feature you must have the correct access rights.
RegDelete, RegEnumKey, RegEnumVal, RegRead
; Write a single REG_SZ value
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey", "REG_SZ", "Hello this is a test")
; Write the REG_MULTI_SZ value of "line1" and "line2"
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey1", "REG_MULTI_SZ", "line1" & @CRLF & "line2")
; Write the REG_MULTI_SZ value of "line1"
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey2", "REG_MULTI_SZ", "line1")
; always add and extra null string
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey3", "REG_MULTI_SZ", "line1" & @CRLF & "line2" & @CRLF)
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey4", "REG_MULTI_SZ", "line1" & @CRLF & @CRLF & "line2" & @CRLF)
; empty REG_MULTI_SZ
RegWrite("HKEY_CURRENT_USER\Software\Test", "TestKey5", "REG_MULTI_SZ", "")
; create just the key
RegWrite("HKEY_CURRENT_USER\Software\Test1")