Packages
 In this topic

*Constructors

*Methods

*Fields

 

Packages   PreviousThis PackageNext
Package com.ms.lang   Previous This
Package
Next

 


Class RegKey

public class RegKey
{
  // Fields
  public final static int CLASSES_ROOT;
  public final static int KEYOPEN_ALL;
  public final static int KEYOPEN_CREATE;
  public final static int KEYOPEN_READ;
  public final static int KEYOPEN_WRITE;
  public final static int LOCALMACHINE_ROOT;
  public final static int USER_ROOT;
  public final static int USERS_ROOT;

  // Constructors
  public RegKey(RegKey rkParent, String subKey, int access)
        throws RegKeyException;
  public RegKey(int rootID, String subKey, int access)
        throws RegKeyException;
  public RegKey(int rootID,String subKey) throws RegKeyException;

  // Methods
  public void close();
  public void deleteSubKey(String sub);
  public void deleteValue(String val);
  public String enumKey(int idx);
  public RegKeyEnumValue enumValue(int idx);
  public void finalize();
  public void flush();
  public byte[] getBinaryValue(String name);
  public int getIntValue(String name);
  public int getIntValue(String name, int defval);
  public final static RegKey getRootKey(int id);
  public String getStringValue(String name);
  public String getStringValue(String name,String defval);
  public void loadKey(String subKey, String fileName);
  public RegQueryInfo queryInfo();
  public void replace(String subKey, String newFile,
        String oldFile);
  public void restore( String filename, boolean vol );
  public void setValue(String subKey, String val);
  public void setValue(String subKey, byte val[]);
  public void setValue(String subKey, int val);
  public String toString();
  public void unload(String subKey);
  public RegKeyValueEnumerator values();
}

The RegKey class produces Windows registry access objects.

Constructors

RegKey

public RegKey(RegKey rkParent, String subKey, int access)
        throws RegKeyException;

Creates the specified key. If the key already exists in the Windows registry, the method opens it.

ParameterDescription
rkParent The currently open key or any of the following predefined reserved identifiers:
  • null
  • HKEY_CLASSES_ROOT,
  • HKEY_CURRENT_USER,
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

The key created is a subkey of the key identified by the rkParent parameter. If the applet is running in a browser or another protected environment, this parameter must be null.

subKey The string specifying the name of a subkey that this method opens or creates. must be a subkey of the key identified by the rkParent parameter. This subkey must not begin with the backslash character (\). The rkParent parameter cannot be null.
access The read-write access privileges for the key.

Exceptions:

com.ms.lang.RegKeyException if the key cannot be created.

RegKey

public RegKey(int rootID, String subKey, int access) throws RegKeyException;

A convenience constructor that performs Regkey.getRootKey automatically.

ParameterDescription
rootID The rootID of the key.
subKey A string specifying the name of a subkey that this method opens or creates. The subkey must not begin with the backslash character (\). The rkParent parameter cannot be null.
access The read-write access for the key.

RegKey

public RegKey(int rootID,String subKey) throws RegKeyException;

Opens a key for reading.

ParameterDescription
rootID The root identifier of the key.
subKey A string specifying the name of a subkey that this method opens or creates. The subkey must not begin with the backslash character (\). This parameter cannot be null.

Methods

close

public void close();

Closes a key when it is no longer needed.

Return Value:

No return value.

Remarks:

As the system registry keys must be written out to disk, the keys must be closed when no longer needed. After this, the keys must not be used again.

deleteSubKey

public void deleteSubKey(String sub);

Removes a subkey from the key.

Return Value:

No return value.

ParameterDescription
sub The subkey removed from the key.

Exceptions:

IOException if the subkey removal is unsuccessful.

deleteValue

public void deleteValue(String val);

Deletes a value from the key.

ParameterDescription
val The name of the value that is deleted.

enumKey

public String enumKey(int idx);

Enumerates a key's subkeys.

Return Value:

Returns the enumeration value of the subkey by index (see RegKeyEnumValue).

ParameterDescription
idx The enumeration index.

enumValue

public RegKeyEnumValue enumValue(int idx);

Enumerates values of the key.

Return Value:

Returns the subkey name of the subkey.

ParameterDescription
idx The enumeration index.

finalize

public void finalize();

Frees the resources associated with a RegKey object.

Return Value:

No return value.

flush

public void flush();

Flushes the key to the registry on disk.

Return Value:

No return value.

getBinaryValue

public byte[] getBinaryValue(String name);

Queries a byte array from the registry.

Return Value:

Returns the byte array contained in the subKey.

ParameterDescription
name The subKey containing the value requested. The name must be a subkey of the current key.

getIntValue

public int getIntValue(String name);

Queries an integer value from the registry.

Return Value:

Returns the integer value contained in the subKey.

ParameterDescription
name The subKey containing the value wanted. The name must be a subkey of the current key.

getIntValue

public int getIntValue(String name, int defval);

Queries an integer value from the registry. The name is a subkey of the current key. If the named value does not exist in the registry, the default value is returned.

Return Value:

Returns the integer value contained in the subKey or the default value if the named value does not exist in the registry.

ParameterDescription
name The subkey containing the value wanted.
defval The default value.

getRootKey

public final static RegKey getRootKey(int id);

Retrieves a top-level key.

ParameterDescription
id The identifier of the top-level key.

getStringValue

public String getStringValue(String name);

Queries a string value from the registry. The name is a subkey of the current key.

Return Value:

Returns the String value contained in the subKey.

ParameterDescription
name The subKey containing the requested value.

getStringValue

public String getStringValue(String name,String defval);

Queries a string value from the registry. The name is a subkey of the current key. If the named value does not exist in the registry, the specified default value is returned.

Return Value:

Returns the default value if the named value does not exist in the registry. Otherwise, the method returns the string value contained in the subkey.

ParameterDescription
name The subkey containing the requested string.
defval The default value to return.

loadKey

public void loadKey(String subKey, String fileName);

Loads a new hive into the registry.

Return Value:

No return value.

ParameterDescription
subKey The name of the subkey created to contain the new hive.
fileName The name of a file that contains the registry information.

queryInfo

public RegQueryInfo queryInfo();

Retrieves information about the key.

Return Value:

Returns a RegQueryInfo object containing the information.

replace

public void replace(String subKey, String newFile, String oldFile);

Replaces the file supporting a key and all its subkeys with another file. The next time the system is started, the key and subkey values are stored in the new file.

Return Value:

No return value.

ParameterDescription
subKey The subkey, whose values are stored in the new file.
newFile The name of the new file.
oldFile The name of the old file.

restore

public void restore( String filename, boolean vol );

Restores a subkey from a file.

Return Value:

No return value.

ParameterDescription
filename The filename.
vol The value returned is true if the hive is volatile; otherwise, the value is false.

setValue

public void setValue(String subKey, String val);

Sets a string value into a subkey.

Return Value:

No return value.

ParameterDescription
subKey The subkey that holds the value.
val The string that is written out.

setValue

public void setValue(String subKey, byte val[]);

Sets a byte array into a subkey.

Return Value:

No return value.

ParameterDescription
subKey The subkey that holds the value.
val The array that is written out.

setValue

public void setValue(String subKey, int val);

Sets an integer value into a subkey.

Return Value:

No return value.

ParameterDescription
subKey The subkey that holds the value.
val The integer that is written out.

toString

public String toString();

Returns a string representation of the key.

Return Value:

Returns a string containing the path information in the form: "[RegKey: <path>]".

unload

public void unload(String subKey);

Unloads a hive from the registry.

Return Value:

No return value.

ParameterDescription
subKey The subkey that is unloaded.

values

public RegKeyValueEnumerator values();

Returns an enumeration of the subkey values of this registry key.

Return Value:

Returns a RegKeyValueEnumerator object, used to enumerate the list of subkeys.

See Also: RegKeyValueEnumerator

Fields

CLASSES_ROOT
An identifier that signifies that the HKEY_CLASSES_ROOT key must be returned.
KEYOPEN_ALL
An identifier that signifies a key must be opened for read-write access.
KEYOPEN_CREATE
An identifier that signifies a key must be created, not opened.
KEYOPEN_READ
An identifier that signifies a key must be opened for read-only access.
KEYOPEN_WRITE
An identifier that signifies a key must be opened for write access.
LOCALMACHINE_ROOT
An identifier that signifies that the HKEY_LOCAL_MACHINE key must be returned.
USER_ROOT
An identifier that signifies that the HKEY_CURRENT_USER key must be returned.
USERS_ROOT
An identifier that signifies that the HKEY_USERS key must be returned.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.