Phantom Documentation

[Help Home] [Phantom Home]
regkey

The regkey data type allows for the opening and reading of Windows system registry keys. The registry key is defined by a path recognized by the Windows system registry. A registry key may contain values associated with it that can be retrieved using the regkey data type.

The regkey data type has the following member variables associated with it:

string Path: The registry key path.
int OpenState: The open state of the regkey. This is 1 if the key is open, 0 if it is closed.
int Handle: The internal numeric handle of the registry key, if it is open.
string PathDelim: The delimiter by which each element of the path is separated by. This is ":" by default.

The path determines which Windows registry key the regkey data type represents. Each element of the path must be separated by the PathDelim parameter.

For example, if PathDelim is "&", an example Path would be:

"HKEY_CURRENT_USER&MyKey1&MyKey2"

The path must include the full path from one of the following base keys:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
HKEY_DYN_DATA


A regkey should be closed after use. However, if it is not closed, the regkey will be closed automatically when either the function or script it was declared in exits.

The regkey data type supports the following member functions:

Close
GetValueCount
GetValues
Open

Example Code

# Declare a regkey
regkey r;
r.Path = "HKEY_CURRENT_USER:Console";

# Display some properties:
disp("--- regkey properties ---");
disp("Path = " + r.Path);
disp("Handle = " + string(r.Handle));
disp("OpenState = " + string(r.OpenState));
disp("PathDelim = " + r.PathDelim);
disp("-------------------------");

# Display the regkey
disp(r);

# Open the regkey, error out if not found
if(!r.Open()){
  exception ex;
  ex.SetError("Could not open regkey");
  ex.throw();
}

# Display the opened regkey
disp(r);

# Get the value count
disp(r.GetValueCount());

# Get the values
string values = r.GetValues("\n", "=");

# Split the values into an array
values = split(values, "\n");

# Display the values
disp("The values are: ");
disp(values);

# Close the registry key
r.Close();



See Also: Variables


Copyright 2000-2011 Phantom Automated Solutions