Skip to content

Registry

Use Registry to add/read/change values in the Windows registry.

Note

On non-Windows platforms this creates an INI file in the executable folder.

First create a new Registry instance, then open or create the key.

import { Registry } from 'miletus';

let reg = new Registry();
let success = await reg.openKey('MyKey', true);
if (success) {
    let myValue = reg.readBool('MyValue');
    //...
}

Methods

new Registry([rootKey, [accessKey]])

  • rootKey RegistryKey - Registry key. Default value is RegistryKey.CURRENT_USER. Supported values:
    • RegistryKey.CLASSES_ROOT
    • RegistryKey.CURRENT_USER
    • RegistryKey.LOCAL_MACHINE
    • RegistryKey.USERS
    • RegistryKey.CURRENT_CONFIG
  • accessKey RegistryAccess - Registry access. Default value is RegistryAccess.KEY_ALL_ACCESS. Supported values:
    • RegistryAccess.KEY_ALL_ACCESS
    • RegistryAccess.KEY_READ
    • RegistryAccess.KEY_WRITE

openKey(key, canCreate)

  • key string - Name of the key.
  • canCreate boolean - Create key if does not exist.

Open a key from the registry.

Returns Promise<boolean> - Resolves with boolean result indicating the success of opening the key.

closeKey()

Close an opened key.

Returns Promise - Resolves when the key is closed.

createKey(key)

  • key string - Name of the key.

Create a new key with given name.

Returns Promise<boolean> - Resolves with boolean result indicating the success of the key creation.

deleteKey(key)

  • key string - Name of the key.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the key deletion.

deleteValue(name)

  • name string - Name of the value to delete.

Remove a specific data value associated with the current key.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the value deletion.

keyExists(key)

  • key string - Name of the key.

Returns Promise<boolean> - Resolves with a boolean value indicating the existence of the key.

valueExists(name)

  • name string - Name of the value.

Returns Promise<boolean> - Resolves with a boolean value indicating the existence of the value.

readBinaryData(name, length)

  • name string - Name of the value.
  • length number - Number of bytes to read.

Read binary data from the current key.

Returns Promise<ArrayBuffer> - Resolves with an ArrayBuffer containing the binary data.

readBool(name)

  • name string - Name of the value.

Read boolean value from the current key.

Returns Promise<boolean> - Resolves with a boolean indicating the value.

readDate(name)

  • name string - Name of the value.

Read date value from the current key.

Returns Promise<Date> - Resolves with a Date indicating the date value. The time part of the Date is 00:00:00.

readDateTime(name)

  • name string - Name of the value.

Read date and time value from the current key.

Returns Promise<Date> - Resolves with a Date indicating the date and time value.

readFloat(name)

  • name string - Name of the value.

Read float value from the current key.

Returns Promise<number> - Resolves with a float number indicating the value.

readInteger(name)

  • name string - Name of the value.

Read integer value from the current key.

Returns Promise<number> - Resolves with an integer number indicating the value.

readString(name)

  • name string - Name of the value.

Read string value from the current key.

Returns Promise<string> - Resolves with a string indicating the value.

readTime(name)

  • name string - Name of the value.

Read time value from the current key.

Returns Promise<Date> - Resolves with a date indicating the time value. The date part of the Date is Januart 1st, 1970.

writeBinaryData(name, value, length)

  • name string - Name of the value.
  • value ArrayBuffer - The value to write.
  • length number - The length (of the data) to write.

Write an ArrayBuffer to the current key.

writeBool(name, value)

  • name string - Name of the value.
  • value boolean - The value to write.

Write a boolean value to the current key.

writeDate(name, value)

  • name string - Name of the value.
  • value Date - The value to write.

Write a Date value to the current key. Only the date part will be persisted.

writeDateTime(name, value)

  • name string - Name of the value.
  • value Date - The value to write.

Write a Date value to the current key. Both date and time will be persisted.

writeFloat(name, value)

  • name string - Name of the value.
  • value number - The value to write.

Write a float value to the current key.

writeInteger(name, value)

  • name string - Name of the value.
  • value number - The value to write.

Write an integer value to the current key.

writeString(name, value)

  • name string - Name of the value.
  • value string - The value to write.

Write a string value to the current key.

writeTime(name, value)

  • name string - Name of the value.
  • value Date - The value to write.

Write a Date value to the current key. Only the time part will be persisted.