install4j API documentation


com.install4j.api.windows
Class WinRegistry

java.lang.Object
  extended by com.install4j.api.windows.WinRegistry

public class WinRegistry
extends java.lang.Object

Collection of static methods to access the Microsoft Windows registry.

Author:
ej-technologies GmbH

Nested Class Summary
static class WinRegistry.ExpandString
          Class to represent Strings with type REG_EXPAND_SZ
 
Field Summary
static int HKEY_CLASSES_ROOT
          Identifies the root registry key HKEY_CLASSES_ROOT.
static int HKEY_CURRENT_CONFIG
          Identifies the root registry key HKEY_CURRENT_CONFIG.
static int HKEY_CURRENT_USER
          Identifies the root registry key HKEY_CURRENT_USER.
static int HKEY_LOCAL_MACHINE
          Identifies the root registry key HKEY_LOCAL_MACHINE.
static int HKEY_USERS
          Identifies the root registry key HKEY_USERS.
 
Method Summary
static boolean createKey(int root, java.lang.String keyName)
          Creates a registry key.
static void deleteKey(int root, java.lang.String keyName, boolean onlyIfEmpty)
          Deletes a registry key.
static void deleteValue(int root, java.lang.String keyName, java.lang.String valueName)
          Deletes a registry value.
static java.lang.String[] getSubKeyNames(int root, java.lang.String keyName)
          Retrieves the sub keys of a registry key.
static java.lang.Object getValue(int root, java.lang.String keyName, java.lang.String valueName)
          Retrieves a registry value.
static boolean keyExists(int root, java.lang.String keyName)
          Checks if a registry key exists.
static boolean setValue(int root, java.lang.String keyName, java.lang.String valueName, java.lang.Object value)
          Sets a registry value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HKEY_CLASSES_ROOT

public static final int HKEY_CLASSES_ROOT
Identifies the root registry key HKEY_CLASSES_ROOT.

See Also:
Constant Field Values

HKEY_CURRENT_USER

public static final int HKEY_CURRENT_USER
Identifies the root registry key HKEY_CURRENT_USER.

See Also:
Constant Field Values

HKEY_LOCAL_MACHINE

public static final int HKEY_LOCAL_MACHINE
Identifies the root registry key HKEY_LOCAL_MACHINE.

See Also:
Constant Field Values

HKEY_USERS

public static final int HKEY_USERS
Identifies the root registry key HKEY_USERS.

See Also:
Constant Field Values

HKEY_CURRENT_CONFIG

public static final int HKEY_CURRENT_CONFIG
Identifies the root registry key HKEY_CURRENT_CONFIG.

See Also:
Constant Field Values
Method Detail

keyExists

public static boolean keyExists(int root,
                                java.lang.String keyName)
Checks if a registry key exists.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
Returns:
true if the key exists.

createKey

public static boolean createKey(int root,
                                java.lang.String keyName)
Creates a registry key.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
Returns:
true if successful.

getValue

public static java.lang.Object getValue(int root,
                                        java.lang.String keyName,
                                        java.lang.String valueName)
Retrieves a registry value. The class of the returned object is determined by the value's type.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
valueName - the name of the registry value.
Returns:
the requested value. Returns null, if the value doesn't exist. Otherwise it is an instance of one of the following classes: String, Integer, String[], byte[], WinRegistry.ExpandString.

setValue

public static boolean setValue(int root,
                               java.lang.String keyName,
                               java.lang.String valueName,
                               java.lang.Object value)
Sets a registry value. The type is determined by the class of the value.

Parameters:
root - one of the HKEY_* constants
keyName - the name of the key without a leading backslash.
valueName - the name of the registry value.
value - an instance of one of the following classes: String, Integer, String[], byte[], WinRegistry.ExpandString.
Returns:
true if successful.

deleteValue

public static void deleteValue(int root,
                               java.lang.String keyName,
                               java.lang.String valueName)
Deletes a registry value.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
valueName - the name of the registry value.

deleteKey

public static void deleteKey(int root,
                             java.lang.String keyName,
                             boolean onlyIfEmpty)
Deletes a registry key.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
onlyIfEmpty - if true, the method will delete the key only if the key contains no values and no subkey.

getSubKeyNames

public static java.lang.String[] getSubKeyNames(int root,
                                                java.lang.String keyName)
Retrieves the sub keys of a registry key.

Parameters:
root - one of the HKEY_* constants.
keyName - the name of the key without a leading backslash.
Returns:
an array with the sub keys' names. Returns an empty array if there are no sub keys and null if the key doesn't exist or if an error occurs.