Class: Registry

Registry


new Registry(options)

Creates a registry object, which provides access to a single registry key.
Note: This class is returned by a call to require('winreg').

Parameters:
Name Type Description
options object

the options

Properties
Name Type Argument Description
host string <optional>

the hostname

hive string <optional>

the hive id

key string <optional>

the registry key

arch string <optional>

the optional registry hive architecture ('x86' or 'x64'; only valid on Windows 64 Bit Operating Systems)

Example
var Registry = require('winreg')
,   autoStartCurrentUser = new Registry({
      hive: Registry.HKCU,
      key:  '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
    });

Members


<readonly> arch :string

The registry hive architecture ('x86' or 'x64').

Type:
  • string

<readonly> hive :string

The hive id.

Type:
  • string

<readonly> host :string

The hostname.

Type:
  • string

<readonly> key :string

The registry key name.

Type:
  • string

<readonly> parent :Registry

Creates a new Registry instance that points to the parent registry key.

Type:

<readonly> path :string

The full path to the registry key.

Type:
  • string

<static> DEFAULT_VALUE :string

The name of the default value. May be used instead of the empty string literal for better readability.

Type:
  • string

<static> HIVES :array

Collection of available registry hive keys.

Type:
  • array

<static> HKCC :string

Registry hive key HKEY_CURRENT_CONFIG.
Note: For writing to this hive your program has to run with admin privileges.

Type:
  • string

<static> HKCR :string

Registry hive key HKEY_CLASSES_ROOT.
Note: For writing to this hive your program has to run with admin privileges.

Type:
  • string

<static> HKCU :string

Registry hive key HKEY_CURRENT_USER.

Type:
  • string

<static> HKLM :string

Registry hive key HKEY_LOCAL_MACHINE.
Note: For writing to this hive your program has to run with admin privileges.

Type:
  • string

<static> HKU :string

Registry hive key HKEY_USERS.
Note: For writing to this hive your program has to run with admin privileges.

Type:
  • string

<static> REG_BINARY :string

Registry value type BINARY.

Type:
  • string

<static> REG_DWORD :string

Registry value type DOUBLE_WORD.

Type:
  • string

<static> REG_EXPAND_SZ :string

Registry value type EXPANDABLE_STRING.

Type:
  • string

<static> REG_MULTI_SZ :string

Registry value type MULTILINE_STRING.

Type:
  • string

<static> REG_NONE :string

Registry value type UNKNOWN.

Type:
  • string

<static> REG_QWORD :string

Registry value type QUAD_WORD.

Type:
  • string

<static> REG_SZ :string

Registry value type STRING.

Type:
  • string

<static> REG_TYPES :array

Collection of available registry value types.

Type:
  • array

Methods


clear(cb)

Remove all subkeys and values (including the default value) from this registry key.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Returns:

this registry key object

Type
Registry

create(cb)

Create this registry key. Note that this is a no-op if the key already exists.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Returns:

this registry key object

Type
Registry

destroy(cb)

Delete this key and all subkeys from the registry.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Returns:

this registry key object

Type
Registry

erase(cb)

Alias for the clear method to keep it backward compatible.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Deprecated:
Returns:

this registry key object

Type
Registry

get(name, cb)

Gets a named value from this registry key.

Parameters:
Name Type Description
name string

the value name, use Registry.DEFAULT_VALUE or an empty string for the default value

cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

item RegistryItem <optional>

the retrieved registry item

Returns:

this registry key object

Type
Registry

keyExists(cb)

Checks if this key already exists.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

exists boolean <optional>

true if a registry key with this name already exists

Returns:

this registry key object

Type
Registry

keys(cb)

Retrieve all subkeys from this registry key.

Parameters:
Name Type Description
cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

items array <optional>

an array of Registry objects

Returns:

this registry key object

Type
Registry

remove(name, cb)

Remove a named value from this registry key. If name is empty, sets the default value of this key.
Note: This key must be already existing.

Parameters:
Name Type Description
name string

the value name, use Registry.DEFAULT_VALUE or an empty string for the default value

cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Returns:

this registry key object

Type
Registry

set(name, type, value, cb)

Sets a named value in this registry key, overwriting an already existing value.

Parameters:
Name Type Description
name string

the value name, use Registry.DEFAULT_VALUE or an empty string for the default value

type string

the value type

value string

the value

cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

Returns:

this registry key object

Type
Registry

valueExists(name, cb)

Checks if a value with the given name already exists within this key.

Parameters:
Name Type Description
name string

the value name, use Registry.DEFAULT_VALUE or an empty string for the default value

cb function

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

exists boolean <optional>

true if a value with the given name was found in this key

Returns:

this registry key object

Type
Registry

values(cb)

Retrieve all values from this registry key.

Parameters:
Name Type Description
cb valuesCallback

callback function

Properties
Name Type Argument Description
err ProcessUncleanExitError <optional>

error object or null if successful

items array <optional>

an array of RegistryItem objects

Returns:

this registry key object

Type
Registry