nsIWindowsRegKey

IID:2555b930-d64f-437e-9be7-0a2cb252c1f4
Inherits From:nsISupports

This interface is designed to provide scriptable access to the Windows registry system ("With Great Power Comes Great Responsibility"). The interface represents a single key in the registry.

This interface is highly Win32 specific.


Constants

Root keys. The values for these keys correspond to the values from WinReg.h in the MS Platform SDK. The ROOT_KEY_ prefix corresponds to the HKEY_ prefix in the MS Platform SDK.

This interface is not restricted to using only these root keys.

PRUint32 ROOT_KEY_CLASSES_ROOT = -2147483648
PRUint32 ROOT_KEY_CURRENT_USER = -2147483647
PRUint32 ROOT_KEY_LOCAL_MACHINE = -2147483646
Values for the mode parameter passed to the open and create methods. The values defined here correspond to the REGSAM values defined in WinNT.h in the MS Platform SDK, where ACCESS_ is replaced with KEY_.

This interface is not restricted to using only these access types.

PRUint32 ACCESS_BASIC = 131072
PRUint32 ACCESS_QUERY_VALUE = 1
PRUint32 ACCESS_SET_VALUE = 2
PRUint32 ACCESS_CREATE_SUB_KEY = 4
PRUint32 ACCESS_ENUMERATE_SUB_KEYS = 8
PRUint32 ACCESS_NOTIFY = 16
PRUint32 ACCESS_READ = 131097
PRUint32 ACCESS_WRITE = 131078
PRUint32 ACCESS_ALL = 131103
Values for the type of a registry value. The numeric values of these constants are taken directly from WinNT.h in the MS Platform SDK. The Microsoft documentation should be consulted for the exact meaning of these value types.

This interface is somewhat restricted to using only these value types. There is no method that is directly equivalent to RegQueryValueEx or RegSetValueEx. In particular, this interface does not support the REG_MULTI_SZ and REG_EXPAND_SZ value types. It is still possible to enumerate values that have other types (i.e., getValueType may return a type not defined below).

PRUint32 TYPE_NONE = 0
PRUint32 TYPE_STRING = 1
PRUint32 TYPE_BINARY = 3
PRUint32 TYPE_INT = 4
PRUint32 TYPE_INT64 = 11

Properties

readonly PRUint32 childCount

This attribute returns the number of child keys.

HKEY key

This attribute exposes the native HKEY and is available to provide C++ consumers with the flexibility of making other Windows registry API calls that are not exposed via this interface.

It is possible to initialize this object by setting an HKEY on it. In that case, it is the responsibility of the consumer setting the HKEY to ensure that it is a valid HKEY.

WARNING: Setting the key does not close the old key.

readonly PRUint32 valueCount

This attribute returns the number of values under this key.


Methods

void close ( ) void create ( PRUint32 rootKey , AString relPath , PRUint32 mode ) nsIWindowsRegKey createChild ( AString relPath , PRUint32 mode ) AString getChildName ( PRUint32 index ) AString getValueName ( PRUint32 index ) PRUint32 getValueType ( AString name ) PRBool hasChanged ( ) PRBool hasChild ( AString name ) PRBool hasValue ( AString name ) PRBool isWatching ( ) void open ( PRUint32 rootKey , AString relPath , PRUint32 mode ) nsIWindowsRegKey openChild ( AString relPath , PRUint32 mode ) ACString readBinaryValue ( AString name ) PRUint64 readInt64Value ( AString name ) PRUint32 readIntValue ( AString name ) AString readStringValue ( AString name ) void removeChild ( AString relPath ) void removeValue ( AString name ) void startWatching ( PRBool recurse ) void stopWatching ( ) void writeBinaryValue ( AString name , ACString data ) void writeInt64Value ( AString name , PRUint64 data ) void writeIntValue ( AString name , PRUint32 data ) void writeStringValue ( AString name , AString data )

void close ( )

This method closes the key. If the key is already closed, then this method does nothing.


void create ( PRUint32 rootKey , AString relPath , PRUint32 mode )

This method opens an existing key or creates a new key.

NOTE: On 32-bit Windows, it is valid to pass any HKEY as the rootKey parameter of this function. However, for compatibility with 64-bit Windows, that usage should probably be avoided in favor of createChild.

Arguments:
rootKey: A root key defined above or any valid HKEY on 32-bit Windows.
relPath: A relative path from the given root key.
mode: Access mode, which is a bit-wise OR of the ACCESS_ values defined above.

nsIWindowsRegKey createChild ( AString relPath , PRUint32 mode )

This method opens or creates a subkey relative to this key.

Arguments:
relPath
mode
Returns:
nsIWindowsRegKey for the newly opened or created subkey.

AString getChildName ( PRUint32 index )

This method returns the name of the n'th child key.

Arguments:
index: The index of the requested child key.

AString getValueName ( PRUint32 index )

This method returns the name of the n'th value under this key.

Arguments:
index: The index of the requested value.

PRUint32 getValueType ( AString name )

This method returns the type of the value with the given name. The return value is one of the "TYPE_" constants defined above.

Arguments:
name: The name of the value to query.

PRBool hasChanged ( )

This method returns true if the key has changed and false otherwise. This method will always return false if startWatching was not called.


PRBool hasChild ( AString name )

This method checks to see if the key has a child by the given name.

Arguments:
name: The name of the requested child key.

PRBool hasValue ( AString name )

This method checks to see if the key has a value by the given name.

Arguments:
name: The name of the requested value.

PRBool isWatching ( )

This method returns true if the key is being watched for changes (i.e., if startWatching() was called).


void open ( PRUint32 rootKey , AString relPath , PRUint32 mode )

This method opens an existing key. This method fails if the key does not exist.

NOTE: On 32-bit Windows, it is valid to pass any HKEY as the rootKey parameter of this function. However, for compatibility with 64-bit Windows, that usage should probably be avoided in favor of openChild.

Arguments:
rootKey: A root key defined above or any valid HKEY on 32-bit Windows.
relPath: A relative path from the given root key.
mode: Access mode, which is a bit-wise OR of the ACCESS_ values defined above.

nsIWindowsRegKey openChild ( AString relPath , PRUint32 mode )

This method opens a subkey relative to this key. This method fails if the key does not exist.

Arguments:
relPath
mode
Returns:
nsIWindowsRegKey for the newly opened subkey.

ACString readBinaryValue ( AString name )

This method reads the binary contents of the named value under this key.

JavaScript callers should take care with the result of this method since it will be byte-expanded to form a JS string. (The binary data will be treated as an ISO-Latin-1 character string, which it is not).

Arguments:
name: The name of the value to query.

PRUint64 readInt64Value ( AString name )

This method reads the 64-bit integer contents of the named value.

Arguments:
name: The name of the value to query.

PRUint32 readIntValue ( AString name )

This method reads the integer contents of the named value.

Arguments:
name: The name of the value to query.

AString readStringValue ( AString name )

This method reads the string contents of the named value as a Unicode string.

Arguments:
name: The name of the value to query. This parameter can be the empty string to request the key's default value.

void removeChild ( AString relPath )

This method removes a child key and all of its values. This method will fail if the key has any children of its own.

Arguments:
relPath: The relative path from this key to the key to be removed.

void removeValue ( AString name )

This method removes the value with the given name.

Arguments:
name: The name of the value to be removed.

void startWatching ( PRBool recurse )

This method starts watching the key to see if any of its values have changed. The key must have been opened with mode including ACCESS_NOTIFY. If recurse is true, then this key and any of its descendant keys are watched. Otherwise, only this key is watched.

Arguments:
recurse: Indicates whether or not to also watch child keys.

void stopWatching ( )

This method stops any watching of the key initiated by a call to startWatching. This method does nothing if the key is not being watched.


void writeBinaryValue ( AString name , ACString data )

This method writes the binary contents of the named value. The value will be created if it does not already exist.

JavaScript callers should take care with the value passed to this method since it will be truncated from a JS string (unicode) to a ISO-Latin-1 string. (The binary data will be treated as an ISO-Latin-1 character string, which it is not). So, JavaScript callers should only pass character values in the range \u0000 to \u00FF, or else data loss will occur.

Arguments:
name: The name of the value to modify.
data: The data for the value to modify.

void writeInt64Value ( AString name , PRUint64 data )

This method writes the 64-bit integer contents of the named value. The value will be created if it does not already exist.

Arguments:
name: The name of the value to modify.
data: The data for the value to modify.

void writeIntValue ( AString name , PRUint32 data )

This method writes the integer contents of the named value. The value will be created if it does not already exist.

Arguments:
name: The name of the value to modify.
data: The data for the value to modify.

void writeStringValue ( AString name , AString data )

This method writes the unicode string contents of the named value. The value will be created if it does not already exist.

Arguments:
name: The name of the value to modify. This parameter can be the empty string to modify the key's default value.
data: The data for the value to modify.

References

This interface is returned from the following methods:

nsIWindowsRegKey.createChild, nsIWindowsRegKey.openChild

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
No comments available

Copyright © 1999 - 2005 XULPlanet.com