Code Monkey home page Code Monkey logo

native-reg's Introduction

native-reg

In-process native node module for Windows registry access. It includes prebuilt binaries for Windows for x86 64-bit and 32-bit, and also ARM 64-bit (tested against unofficial Node.js builds, as it is not currently supported).

There are no fallbacks for other (future?) Windows targets, though requests are welcome.

If not running on Windows, the module will not fail to load in order to simplify cross-platform bundling, but it will assert if any of the functions are called.

Example

const reg = require('native-reg');

const key = reg.openKey(
  reg.HKCU,
  'Software\\MyCompany\\MySoftware',
  reg.Access.ALL_ACCESS);

const version = reg.getValue(key, 'Install', 'Version');

if (isOldVersion(version)) {
    reg.deleteTree(key, 'Install');
    
    const installKey = reg.createKey(key, 'Install', reg.Access.ALL_ACCESS);
    reg.setValueSZ(installKey, 'Version', newVersion);
    // ...
    reg.closeKey(installKey);
}

reg.closeKey(key);

API

Read each API's linked Windows documentation for details on functionality and usage.

Contents:

Errors

The API initially validates the arguments with the standard node assert library:

try {
  // Should not be 'HKLM', but reg.HKLM or reg.HKEY.LOCAL_MACHINE
  reg.openKey('HKLM', 'SOFTWARE\\Microsoft\\Windows', reg.Access.READ);
  assert.fail();
} catch (e) {
  assert(e instanceof require('assert').AssertionError);
}

If the wrapped Windows API returns an error, with a couple of exceptions for commonly non-failure errors (e.g. key does not exist), are thrown as JS Errors with the generic error message, e.g.: Access is denied., but additional standard errno and syscall properties, for example, a common error is trying to use Access.ALL_ACCESS on reg.HKLM, which you need UAC elevation for:

try {
  // Assuming you are not running as administrator!
  reg.openKey(reg.HKLM, 'SOFTWARE\\Microsoft\\Windows', reg.Access.ALL_ACCESS);
  assert.fail();
} catch (e) {
  assert.strictEqual(e.message, 'Access is denied.');
  assert.strictEqual(e.errno, 5);
  assert.strictEqual(e.syscall, 'RegOpenKeyExW');
}

Constants

This library uses Typescript enums for constants, this generates a two way name <-> value mapping.

For example: Access.SET_VALUE is 0x0002, and Access[2] is "SET_VALUE".

HKEY enum

Exports the set of predefined HKEYs.

createKey, openKey, loadAppKey and openCurrentUser will return other values for HKEYs, which at the moment are objects with a single property native with the native HKEY handle as a V8 External value, for use in other native packages, or null after it is closed. For these values you can call closeKey once you are done to clean up early, but they will be closed by the garbage collector if you chose not to.

export enum HKEY {
  CLASSES_ROOT                   = 0x80000000,
  CURRENT_USER                   = 0x80000001,
  LOCAL_MACHINE                  = 0x80000002,
  USERS                          = 0x80000003,
  PERFORMANCE_DATA               = 0x80000004,
  PERFORMANCE_TEXT               = 0x80000050,
  PERFORMANCE_NLSTEXT            = 0x80000060,
  CURRENT_CONFIG                 = 0x80000005,
  DYN_DATA                       = 0x80000006,
  CURRENT_USER_LOCAL_SETTINGS    = 0x80000007,
}
Shorthands

Also exports the standard shorthand HKEY names:

export const HKCR = HKEY.CLASSES_ROOT;
export const HKCU = HKEY.CURRENT_USER;
export const HKLM = HKEY.LOCAL_MACHINE;
export const HKU = HKEY.USERS;
isHKEY

Helper returns if the argument is a valid-looking HKEY. Most APIs will throw an assertion error if hkey that does not return true for this is used.

Valid HKEY values are,

  • The values of the HKEY enum
  • Objects returned from createKey, openKey, loadAppKey and openCurrentUser
  • External values that represent HKEYs (for example, from another node addon)
  • Non-0 32-bit values that represent the pointer value of HKEYs (for example, from another node addon) - not that this is unreliable on 64-bit applications, and should be avoided.
export function isHKEY(hkey: any): boolean;

Access enum

Specifies access checks for opened or created keys. Not always enforced for opened keys:

Certain registry operations perform access checks against the security descriptor of the key, not the access mask specified when the handle to the key was obtained. For example, even if a key is opened with a samDesired of KEY_READ, it can be used to create registry keys if the key's security descriptor permits. In contrast, the RegSetValueEx function specifically requires that the key be opened with the KEY_SET_VALUE access right.

// from https://docs.microsoft.com/en-nz/windows/desktop/SysInfo/registry-key-security-and-access-rights
export enum Access {
  // Specific rights
  QUERY_VALUE         = 0x0001,
  SET_VALUE           = 0x0002,
  CREATE_SUB_KEY      = 0x0004,
  ENUMERATE_SUB_KEYS  = 0x0008,
  NOTIFY              = 0x0010,
  CREATE_LINK         = 0x0020,

  // WOW64. See https://docs.microsoft.com/en-nz/windows/desktop/WinProg64/accessing-an-alternate-registry-view
  WOW64_64KEY         = 0x0100,
  WOW64_32KEY         = 0x0200,

  // Generic rights.
  READ              = 0x2_0019,
  WRITE             = 0x2_0006,
  EXECUTE           = READ,

  ALL_ACCESS        = 0xF_003F,
}

ValueType enum

Types for registry values. See documentation.

export enum ValueType  {
  NONE                       = 0, // No value type
  SZ                         = 1, // Unicode nul terminated string
  EXPAND_SZ                  = 2, // Unicode nul terminated string
                                  // (with environment variable references)
  BINARY                     = 3, // Free form binary
  DWORD                      = 4, // 32-bit number
  DWORD_LITTLE_ENDIAN        = 4, // 32-bit number (same as REG_DWORD)
  DWORD_BIG_ENDIAN           = 5, // 32-bit number
  LINK                       = 6, // Symbolic Link (unicode)
  MULTI_SZ                   = 7, // Multiple Unicode strings
  RESOURCE_LIST              = 8, // Resource list in the resource map
  FULL_RESOURCE_DESCRIPTOR   = 9, // Resource list in the hardware description
  RESOURCE_REQUIREMENTS_LIST = 10,
  QWORD                      = 11, // 64-bit number
  QWORD_LITTLE_ENDIAN        = 11, // 64-bit number (same as REG_QWORD)
}

Raw APIs

These APIs fairly directly wrap the Windows API linked, only abstracting some of the allocation and general usage style.

The exception is enumKeyNames and enumValueNames which iterate to build a list and only return the names, and not other properties.

Value type

Raw registry values returned from queryValueRaw and getValueRaw are simply Node Buffers with an additional type property from ValueType:

export type Value = Buffer & { type: ValueType };

createKey

Wraps RegCreateKeyExW

Creates the specified registry key. If the key already exists, the function opens it. Note that key names are not case sensitive.

You must call closeKey on the result to clean up.

export function createKey(
  hkey: HKEY,
  subKey: string,
  access: Access,
  options: CreateKeyOptions = 0,
): HKEY;

export enum CreateKeyOptions {
  NON_VOLATILE = 0,
  VOLATILE = 1,
  CREATE_LINK = 2,
  BACKUP_RESTORE = 4,
}

openKey

Wraps RegOpenKeyExW

Opens the specified registry key. Note that key names are not case sensitive.

Returns null if subKey does not exist under hkey.

You must call closeKey on the result to clean up.

export function openKey(
  hkey: HKEY,
  subKey: string,
  access: Access,
  options: OpenKeyOptions = 0,
): HKEY | null;

export enum OpenKeyOptions {
  OPEN_LINK = 8,
}

loadAppKey

Wraps RegLoadAppKeyW

Loads the specified registry hive as an application hive.

You must call closeKey on the result to clean up.

export function loadAppKey(
  file: string,
  access: Access,
): HKEY;

openCurrentUser

Wraps RegOpenCurrentUser

Retrieves a handle to the HKEY_CURRENT_USER key for the user the current thread is impersonating.

Only makes sense to use if you have access to Windows user impersonation. Maybe take a look at my currently WIP Windows user account package.

You must call closeKey on the result to clean up.

export function openCurrentUser(access: Access): HKEY;

enumKeyNames

Wraps RegEnumKeyExW iterated to get the sub key names for a key.

Enumerates the subkeys of the specified open registry key.

export function enumKeyNames(hkey: HKEY): string[];

enumValueNames

Wraps RegEnumValueW iterated to get the value names for a key.

Enumerates the values for the specified open registry key.

export function enumValueNames(hkey: HKEY): string[];

queryValueRaw

Wraps RegQueryValueExW without additional parsing.

Retrieves the type and data for the specified value name associated with an open registry key.

You may want to use queryValue instead.

Returns null if valueName does not exist under hkey.

export function queryValueRaw(
  hkey: HKEY,
  valueName: string | null,
): Value | null;

getValueRaw

Wraps RegGetValueW without additional parsing.

Retrieves the type and data for the specified registry value.

You may want to use getValue instead.

Returns null if subKey or valueName does not exist under hkey.

export function getValueRaw(
  hkey: HKEY,
  subKey: string | null,
  valueName: string | null,
  flags: GetValueFlags = 0,
): Value | null;

export enum GetValueFlags {
  RT_ANY = 0xffff,
  RT_REG_NONE = 0x0001,
  RT_REG_SZ = 0x0002,
  RT_REG_EXPAND_SZ = 0x0004,
  RT_REG_BINARY = 0x0008,
  RT_REG_DWORD = 0x0010,
  RT_REG_MULTI_SZ = 0x0020,
  RT_REG_QWORD = 0x0040,
  RT_DWORD = RT_REG_DWORD | RT_REG_BINARY,
  RT_QWORD = RT_REG_QWORD | RT_REG_BINARY,

  NO_EXPAND = 0x10000000,
  // ZEROONFAILURE = 0x20000000, // doesn't make sense here
  SUBKEY_WOW6464KEY = 0x00010000,
  SUBKEY_WOW6432KEY = 0x00020000,
}

setValueRaw

Wraps RegSetValueExW

Sets the data and type of a specified value under a registry key.

export function setValueRaw(
  hkey: HKEY,
  valueName: string | null,
  valueType: ValueType,
  data: Buffer,
): void;

renameKey

Wraps RegRenameKey

Changes the name of the specified registry key.

export function renameKey(
  hkey: HKEY,
  subKey: string | null,
  newSubKey: string,
): void;

copyTree

Wraps RegCopyTreeW

Copies the specified registry key, along with its values and subkeys, to the specified destination key.

export function copyTree(
  hkeySrc: HKEY,
  subKey: string | null,
  hkeyDest: HKEY,
): void;

deleteKey

Wraps RegDeleteKeyW

Deletes a subkey and its values. Note that key names are not case sensitive.

Returns true if the key existed before it was deleted.

export function deleteKey(
  hkey: HKEY,
  subKey: string,
): boolean;

deleteTree

Wraps RegDeleteTreeW

Deletes the subkeys and values of the specified key recursively.

Returns true if the key existed before it was deleted.

export function deleteTree(
  hkey: HKEY,
  subKey: string | null,
): boolean;

deleteKeyValue

Wraps RegDeleteKeyValueW

Removes the specified value from the specified registry key and subkey.

Returns true if the value existed before it was deleted.

export function deleteKeyValue(
  hkey: HKEY,
  subKey: string,
  valueName: string,
): boolean;

deleteValue

Wraps RegDeleteValueW

Removes a named value from the specified registry key. Note that value names are not case sensitive.

Returns true if the value existed before it was deleted.

export function deleteValue(
  hkey: HKEY,
  valueName: string | null,
): boolean;

closeKey

Wraps RegCloseKey

Closes a handle to the specified registry key.

For convenience, null or undefined values are allowed and ignored.

export function closeKey(hkey: HKEY | null | undefined): void;

Format helpers

parseValue

Returns the JS-native value for common Value types:

  • SZ, EXPAND_SZ -> string
  • BINARY -> Buffer
  • DWORD / DWORD_LITTLE_ENDIAN -> number
  • DWORD_BIG_ENDIAN -> number
  • MULTI_SZ -> string[]
  • QWORD / QWORD_LITTLE_ENDIAN -> bigint

Throws an assertion error if the type is not one of the above!

For convenience, passes through null so missing values don't have to be specially treated.

export type ParsedValue = number | bigint | string | string[] | Buffer;
export function parseValue(value: Value | null): ParsedValue | null;

parseString

Parses SZ and EXPAND_SZ (etc.) registry values.

export function parseString(value: Buffer): string;

parseMultiString

Parses MULTI_SZ registry values.

export function parseMultiString(value: Buffer): string[];

formatString

Formats a string to SZ, EXPAND_SZ (etc.) format.

export function formatString(value: string): Buffer;

formatMultiString

Formats an array of strings to MULTI_SZ format.

export function formatMultiString(values: string[]): Buffer;

formatDWORD

Formats a number to DWORD / DWORD_LITTLE_ENDIAN format.

export function formatDWORD(value: number): Buffer;

formatQWORD

Formats a number or bigint to QWORD format.

export function formatQWORD(value: number | bigint): Buffer;

Formatted value APIs

These APIs wrap the raw value APIs with the formatting helpers.

setValue{Type}

A set of wrappers that sets the registry value using setValueRaw with the appropriate ValueType and format helper.

For example, setValueSZ is setValueRaw(hkey, valueName, ValueType.SZ, formatString(value)).

export function setValueSZ(
  hkey: HKEY,
  valueName: string | null,
  value: string,
): void;
export function setValueEXPAND_SZ(
  hkey: HKEY,
  valueName: string | null,
  value: string,
): void;
export function setValueMULTI_SZ(
  hkey: HKEY,
  valueName: string | null,
  value: string[],
): void;
export function setValueDWORD(
  hkey: HKEY,
  valueName: string | null,
  value: number,
): void;
export function setValueQWORD(
  hkey: HKEY,
  valueName: string | null,
  value: number | bigint,
): void;

getValue

Wraps getValueRaw in parseValue.

export function getValue(
  hkey: HKEY,
  subKey: string | null,
  valueName: string | null,
  flags: GetValueFlags = 0,
): ParsedValue | null;

queryValue

Wraps queryValueRaw in parseValue.

export function queryValue(
  hkey: HKEY,
  valueName: string | null,
): ParsedValue | null;

native-reg's People

Contributors

clemp6r avatar cwalther avatar dependabot[bot] avatar m417z avatar simonbuchan avatar thegecko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

native-reg's Issues

Error when using this awesome module in Electron

Hi,

When I use this module in pure node, everything is fine.

However, when I load it in an Electron app, the app crashes when hitting reg.getValue

This is how I'm using it:

function getOutlookVersionPresent(): void {
  console.info("getOutlookVersionPresent - IN");
  try {
    const key = reg.openKey(
      reg.HKLM,
      "SOFTWARE\\Classes\\Outlook.Application\\CurVer",
      reg.Access.READ
    );
    console.warn("Something goes wrong here (In Electron)");
    const version = reg.getValue(key, "", ""); // default value
    console.info(`getOutlookVersionPresent - version:[${version}]`);
    reg.closeKey(key);
  } catch (e) {
    console.error("getOutlookVersionPresent - failure", e);
  }
}

The app crashes and this error message is printed:

#
# Fatal error in , line 0
# ignored
#
#
#
#FailureMessage Object: 00F7E16Cnpm ERR! code ELIFECYCLE

This is my repository.

To reproduce this issue, you just have to fire these commands:

$ npm install
$ npm start

Electron version (Windows ofc): 8.0.3 (tried both x86 & x64)
native-reg version: 0.3.3

I also tried to not use prebuilds and build the package from source but that didn't work either.

In pure node, this works perfectly.

What am I doing wrong?

Thanks in advance!

0.3.0 fails to install for ia32

Trying to install release 0.3.0 from npm with node-v8.16.2-win-x86 (for which no prebuild is included) fails with Error: Cannot find module 'node-addon-api'.

Log
X:\node32test>node --version
v8.16.2

X:\node32test>node -e console.log(process.arch)
ia32

X:\node32test>npm --version
6.12.0

X:\node32test>npm install native-reg
                                                                                                                        s\.staging\node-gyp-build-db3562f8 (1407ms)
> [email protected] install X:\node32test\node_modules\native-reg
> node-gyp-build


X:\node32test\node_modules\native-reg>if not defined npm_config_node_gyp (node "node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
module.js:550
    throw err;
    ^

Error: Cannot find module 'node-addon-api'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at [eval]:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at Object.runInThisContext (vm.js:139:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:653:30)
    at evalScript (bootstrap_node.js:479:27)
gyp: Call to 'node -p "require('node-addon-api').gyp"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (node_modules\npm\node_modules\node-gyp\lib\configure.js:351:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "node.exe" "node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd X:\node32test\node_modules\native-reg
gyp ERR! node -v v8.16.2
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'X:\node32test\package.json'
npm WARN node32test No description
npm WARN node32test No repository field.
npm WARN node32test No README data
npm WARN node32test No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Walther\AppData\Roaming\npm-cache\_logs\2019-12-06T07_50_47_256Z-debug.log

X:\node32test>         

I can fix that by moving node-addon-api from devDependencies to dependencies in package.json. It’s a bit of a shame to have another megabyte of dependencies that is not needed in all cases, but at least it doesn’t have any subdependencies.

In addition, the following change would prebuild binaries for both 32- and 64-bit runtimes. It restricts development to environments that have compilers for both of these architectures though, so I leave it up to you whether that is worth it. (And it increases the package size by 60 kB.)

diff --git a/package.json b/package.json
index b34b1e5..f0ed6b0 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
     "clean": "rimraf build lib prebuilds",
     "build": "npm run build:js && npm run build:bindings",
     "build:js": "tsc -p src",
-    "build:bindings": "prebuildify --napi --target [email protected]",
+    "build:bindings": "prebuildify --napi --target [email protected] --arch x64 && prebuildify --napi --target [email protected] --arch ia32",
     "test": "node test"
   },
   "dependencies": {

By the way, I notice that the 0.3.0 tarball on npm includes the .idea folder, even though it is not mentioned in files in package.json. Any idea what happened there?

Add copyTree and renameKey

copyTree can be implemented with RegCopyTreeW, and renameKey can be implemented with RegRenameKey. Both functions are available since Windows Vista, and the wrapper should be straightforward.

RegRenameKey is not documented, but the function exists, unchanged, since Windows Vista, and is declared in the SDK headers. For such a basic operation, I think that it's worth using an undocumented function.

Update the prebuilt target from 8.12.0 to 14.17.0

When using this module inside an electron project with electron-forge (6.0.0-beta.61) using node 14.x, I was having issues with prebuilds.

 Uncaught Exception:
Error: No native build was found for platform= win32 arch=x64 runtime= electron abi= 89 uv=1 libc=glib node= 14.17.0 electron=14.0.1 webpack=true

The solution for me was to make native-reg build with the target 14.17.0:

 "build:x64": "prebuildify --napi --target [email protected] --cwd binding --arch x64",

Would you agree to do this change? I can prepare a PR for this change.

"os" in package.json is causing issues in webpack build

When using this package, my CI is failing due to this error

 npm ERR! notsup Unsupported platform for [email protected]: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"x64"})

so I installed native-reg as an optional dependency in order to skip it if the OS is not Windows.

Now I get this error when webpack builds the app

Module not found: Error: Can't resolve 'native-reg' 

I couldn't find a good solution to this issue

To fix this, I'm using my fork right now in which I removed the os property from package.json

BINARY Type

hello,
How to add BINARY type in registry ?

Gracefully "Building" on macOS

Yes, I know this module is for windows... πŸ˜„

My Electron app runs on both Windows/Mac. I use node-machine-id for powering my app's licensing. One of the forks uses native-reg and it works great on Windows. However, it breaks the macOS builds. Is there a way to add a no-op in the build process for non-Windows platforms?

Reference: automation-stack/node-machine-id#56 (comment)

> [email protected] electron-rebuild ~/app
> node -r ../internals/scripts/BabelRegister.js ../internals/scripts/ElectronRebuild.js

βœ– Rebuild Failed

An unhandled error occurred inside electron-rebuild
internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module 'node-addon-api'
Require stack:
- ~/app/node_modules/native-reg/[eval] <---- **native-reg**
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at [eval]:1:1
    at Script.runInThisContext (vm.js:116:20)
    at Object.runInThisContext (vm.js:306:38)
    at Object.<anonymous> ([eval]-wrapper:9:26)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at evalScript (internal/process/execution.js:80:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    β€˜~/app/node_modules/native-reg/[eval]'
  ]
}
gyp: Call to 'node -p "require('node-addon-api').gyp"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 

fatal error: 'windows.h' file not found on macOS when using electron-rebuild to rebuild native-reg in Electron apps

Hi,

  • We are using native-reg in our Electron project in Windows OS versions only, while we don't use it in macOS versions.
  • Electron-builder now is using electron-rebuild to rebuild the native dependencies (electron-userland/electron-builder#7196), but when re-building native-reg, Here is the error I got:
/Users/omaralfroukh/Desktop/project/node_modules/node-addon-api/napi.h:32:6: error: Exception support not detected.       Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS.
    #error Exception support not detected. \
     ^
../reg.cc:4:10: fatal error: 'windows.h' file not found
#include <windows.h>
         ^~~~~~~~~~~
2 errors generated.
make: *** [Release/obj.target/reg/reg.o] Error 1
  β¨― node-gyp failed to rebuild '/Users/omaralfroukh/Desktop/project/node_modules/@aabuhijleh/native-reg'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
  • I'm not an expert in the native modules, but I think to fix that issue we have to add a condition to using this library on Windows OS only, here is the fix that needs to add to binding.gyp file:
"conditions": [
        [
          "OS==\"win\"",
          {
            "sources": ["reg.cc"]
          }
        ]
      ],
  • So binding.gyp file should be something like this:
{
  "targets": [
    {
      "target_name": "reg",
      "dependencies": [
        "<!(node -p \"require('node-addon-api').gyp\")"
      ],
      "include_dirs": [
        "<!@(node -p \"require('node-addon-api').include\")",
      ],
      "conditions": [
        [
          "OS==\"win\"",
          {
            "sources": ["reg.cc"]
          }
        ]
      ],
      "msvs_settings": {
        "VCCLCompilerTool": {
          "AdditionalOptions": [
            "/std:c++17"
          ],
          "ExceptionHandling": 1
        },
      }
    }
  ]
}

Thanks a lot!

Can't read Registry value

Hello, i made this code but return null .

const reg = require('native-reg');

const key = reg.openKey(
reg.HKLM,
'SOFTWARE\Microsoft\Windows NT\CurrentVersion',
reg.Access.ALL_ACCESS);

const version = reg.getValue(key, 'Install', 'CurrentBuild');

I want to read CurrentBuild from registry in this path 'SOFTWARE\Microsoft\Windows NT\CurrentVersion'.

This package is just awesome 😍

Recently in hyper (vercel/hyper#4190) we needed a module that would read and write to Registry correctly, the one we were using was dealing with unicode incorrectly.
After trying out nearly all the popular packages, nothing seemed to work, and I came upon this package.
And it's the best out there (see my comparison vercel/hyper#4190 (comment))

Thanks for this awesome project, keep up the good work πŸ‘.
P.S. Just wanted to say this so ended up opening this issue, you can close it.

Registry.createKey or .openKey - cannot read property 'createKey' of undefined

Hi ,

My project import native-reg library and using createKey or openKey runtime exception.

import Registry from "native-reg";

export const getRegisterConfig = async () => {
try{
const regKey = Registry.openKey(Registry.HKCU, "Environment", Registry.Access.ALL_ACCESS);
Registry.closeKey(regKey);
} catch ( error)
{
console.log("error
", error)
}

}

call to function getRegisterConfig();

console log output --> error TypeError: Cannot read property 'openKey' of undefined

thank you

ARM64 support

Hi.

We're making an Windows ARM64 build for our electron application and native-reg is crashing with the following message:

No native build was found for platform=win32 arch=arm64 runtime=electron abi=106 uv=1 arm=8 libc=glibc node=16.14.2 electron=19.0.6

Is that a missing support on native-reg or am I missing something to make it work?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.