Core Function RegWrite

From Sputnik Wiki
Jump to: navigation, search
RegWrite( <key>, <value>, <type>, <data> )

Contents

Description

Sets a value in the registry

Parameters

key

The registry key to read.

value

The value to read.

type

Type of key to write:

"REG_DWORD"              Int32
"REG_QWORD"              Int64
"REG_SZ"                 String
"REG_EXPAND_SZ"          Expandable Stgring
"REG_MULTI_SZ"           Array of strings
"REG_BINARY"             Binary data

Return Value

Success: Returns true.

Failure: Returns false.

Remarks

A registry key must start with:

"HKEY_LOCAL_MACHINE" or "HKLM"

"HKEY_USERS" or "HKU"

"HKEY_CURRENT_USER" or "HKCU"

"HKEY_CLASSES_ROOT" or "HKCR"

"HKEY_CURRENT_CONFIG" or "HKCC"

Example

Long names

RegWrite(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestSTRING", "REG_SZ", "Hello");
RegWrite(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestDWORD", "REG_DWORD", 777);
RegWrite(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestQWORD", "REG_QWORD", 111);
say RegRead(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestSTRING"); // Prints: Hello
say RegRead(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestDWORD"); // Prints: 777
say RegRead(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestQWORD"); // Prints: 111

Short names

RegWrite(@"HKCU\SOFTWARE\Test", @"TestSTRING", "REG_SZ", "Hello");
RegWrite(@"HKCU\SOFTWARE\Test", @"TestDWORD", "REG_DWORD", 777);
RegWrite(@"HKCU\SOFTWARE\Test", @"TestQWORD", "REG_QWORD", 111);
say RegRead(@"HKCU\SOFTWARE\Test", @"TestSTRING"); // Prints: Hello
say RegRead(@"HKCU\SOFTWARE\Test", @"TestDWORD"); // Prints: 777
say RegRead(@"HKCU\SOFTWARE\Test", @"TestQWORD"); // Prints: 111

No type set so it will try guess the type

RegWrite(@"HKCU\SOFTWARE\Test", @"Test", "", "Hello");
say RegRead(@"HKCU\SOFTWARE\Test", @"Test"); // Prints: Hello

Reading and writing binary

// Create binary from a string
$binary = Pack("A*", "Hello World!");
// Write it to reg
RegWrite(@"HKCU\SOFTWARE\Test", @"TestBINARY", "REG_BINARY", $binary);
// Read it from reg
my $var = RegRead(@"HKCU\SOFTWARE\Test", @"TestBINARY");
// Print information
println("The binary size is: " . BinaryLen($var) );
Foreach ($var as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
}
$String = Unpack("A*", $var, 3);
println("Full string: " . $String); // Back to string

Reading and writing arrays

// Make array
$myarray = array("One", "Two", "Three", "Four", 777, 100.42);
// Write array to reg
RegWrite(@"HKCU\SOFTWARE\Test", @"TestARRAY", "REG_MULTI_SZ", $myarray);
 
// Read array from reg
my $var = RegRead(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestARRAY");
// Print the array
printr($var);
/*
Prints:
ARRAY
{
        [0] => One
        [1] => Two
        [2] => Three
        [3] => Four
        [4] => 777
        [5] => 100.42
}
*/

Reading and writing arrays as a string

/ /When writing a REG_MULTI_SZ key you must
// separate each value with @LF ("\n" can be added to string to this effect).
// The value must NOT end with @LF (a newline)
// unless you want an empty substring
 
// Make array
$mystring = "One\nTwo\nThree\nFour\n777\n100.42";
// Write array to reg
RegWrite(@"HKCU\SOFTWARE\Test", @"TestARRAY", "REG_MULTI_SZ", $mystring);
 
// Read array from reg
my $var = RegRead(@"HKEY_CURRENT_USER\SOFTWARE\Test", @"TestARRAY");
// Print the array
printr($var);
/*
Prints:
ARRAY
{
        [0] => One
        [1] => Two
        [2] => Three
        [3] => Four
        [4] => 777
        [5] => 100.42
}
*/
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox