Core Function RegRead

From Sputnik Wiki
Jump to: navigation, search
RegRead( <key>, <value>, <default> )

Contents

Description

Reads a value from the registry

Parameters

key

The registry key to read.

value

The value to read.

default

Optional; The value to return if the read failed.

(Default: "" empty string)

Return Value

Success: Returns the correct data.

Failure: Returns the default data.

Major Failure: Returns null.

Remarks

None.

Example

my $var = RegRead(@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion", @"ProgramFilesDir");
MsgBox("Program files are in: $var");

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