Function Reference

RegWrite

Creates a key or value in the registry.

RegWrite ( "keyname" [,"valuename", "type", value] )

 

Parameters

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", or "REG_BINARY".
value [optional] The value to write.

 

Return Value

Success: Returns 1.
Failure: Returns 0 if error writing registry key or value.

 

Remarks

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").

AutoIt supports registry keys of type REG_BINARY, REG_SZ, REG_MULTI_SZ, REG_EXPAND_SZ, and REG_DWORD.

To access the (Default) value use "" (a blank string) for the valuename.

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 value with @LF. The value must NOT end with @LF and no "blank" entries are allowed (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 on NT/2000/XP/2003, or if you are using a 9x based OS the remote PC must have the remote regsitry service installed first (See Microsoft Knowledge Base Article - 141460).

 

Related

RegDelete, RegRead

 

Example


; Write a single REG_SZ value
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_SZ", "Hello this is a test")


; Write the REG_MULTI_SZ value of "line1" and "line2"
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_MULTI_SZ", "line1" & @LF & "line2")

; INCORRECT uses of REG_MULTI_SZ
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_MULTI_SZ", "line1" & @LF & "line2" & @LF)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_MULTI_SZ", "line1" & @LF & @LF & "line2" & @LF)