Module basic module

moduleregistry

The registry module is a module that operates the Windows Registry. It provides methods and constants to access the registry, which can read, modify, delete, add and other operations. The registry module provides operations similar to those used by Windows applications, but provides the capabilities in FibJS. Constants include common Root, data type and other constants, as well as some constants used for return values ​​of different operations.

Commonly used functions are:

  1. get(root, key[, flags]): Get the value of the specified registry key.
  2. set(root, key, value[, type]): Set the value of the specified registry key.
  3. del(root, key): Delete the specified registry key.

Next, we verify that the key value of a certain registry key exists on the specified registry branch, and then read the key value. If it does not exist, the key value is written to the specified registry key. The code looks like this:

1 2 3 4 5 6 7 8 9 10
var registry = require('registry'); // specify the key name var key = "Software\\Fibjs\\Test\\KeyName"; if (!registry.get(registry.CLASSES_ROOT, key)) { registry.set(registry.CLASSES_ROOT, key, "test_value"); } // specify the key name var value = registry.get(registry.CLASSES_ROOT, key); console.log(value);

The program first verifies whether the registry key exists, and if it does not exist, it writes to the registry with the key name Software\Fibjs\Test\KeyName and sets the value to test_value. Finally, read the key value of the registry and output it on the console. The above code shows the basic usage of the registry module. You can use this module to easily read, modify, add, and delete information in the registry.

static function

listSubKey

Returns all subkeys under the specified key value

1 2
static NArray registry.listSubKey(Integer root, String key);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value

Return results:

  • NArray, returns all subkeys under this key value

listValue

Returns the keys of all data under the specified key value

1 2
static NArray registry.listValue(Integer root, String key);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value

Return results:

  • NArray, returns the keys of all data under the key value

get

Query the numerical value of the specified key value

1 2
static Value registry.get(Integer root, String key);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value

Return results:

  • Value, returns the numerical value of the specified key value

set

Set the specified key value to a number

1 2 3 4
static registry.set(Integer root, String key, Number value, Integer type = DWORD);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value
  • value:Number, specify number
  • type: Integer, specify the type, the allowed types are DWORD and QWORD, the default is DWORD

Set the specified key value to a string

1 2 3 4
static registry.set(Integer root, String key, String value, Integer type = SZ);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value
  • value: String, specified string
  • type: Integer, specify the type, the allowed types are SZ and EXPAND_SZ, the default is SZ

Set the specified key value to a multi-string

1 2 3
static registry.set(Integer root, String key, Array value);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value
  • value: Array, specifies a multi-string array

Set the specified key value to binary

1 2 3
static registry.set(Integer root, String key, Buffer value);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value
  • value:Buffer, specify binary data

del

Delete the value of the specified key value

1 2
static registry.del(Integer root, String key);

Call parameters:

  • root: Integer, specify the registry root
  • key: String, specify key value

constant

CLASSES_ROOT

Registry root, which stores a detailed list of file types recognized by Windows, and their associated programs

1
const registry.CLASSES_ROOT = 0;

CURRENT_USER

Registry root, which stores information set by the current user

1
const registry.CURRENT_USER = 1;

LOCAL_MACHINE

Registry root, including information about the hardware and software installed on the computer

1
const registry.LOCAL_MACHINE = 2;

USERS

The registry root, which contains information about the users who use the computer

1
const registry.USERS = 3;

CURRENT_CONFIG

Registry root, this branch contains the computer's current hardware configuration information

1
const registry.CURRENT_CONFIG = 5;

SZ

Registry data type, string

1
const registry.SZ = 1;

EXPAND_SZ

Registry data type, extended string

1
const registry.EXPAND_SZ = 2;

DWORD

Registry data type, 32-bit value

1
const registry.DWORD = 4;

QWORD

Registry data type, 64-bit value

1
const registry.QWORD = 11;