npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

regodit

v2.4.0

Published

Read/Write Windows Registry using FFI and GoLang (x86, x64 and arm64)

Downloads

41

Readme

About

Read/Write Windows Registry using FFI and GoLang (x86, x64 and arm64).

Friendly API which takes care of the Windows' registry little annoyances. Syntax is inspired from InnoSetup's Pascal Scripting Registry functions.

Originally created to demonstrate that you can bind GoLang as a c-shared DLL to Node via FFI (Go>=1.10).

Example

import * as regedit from "regodit"; //sync
import * as regedit from "regodit/promises"; //async

//Reading
const steamPath = regedit.regQueryStringValue("HKCU", "Software/Valve/Steam", "steamPath");
const accel = regedit.regQueryIntegerValue("HKCU", "Software/Valve/Steam", "H264HWAccel");

//Writing
regedit.regWriteStringValue("HKCU", "Software/Valve/Steam", "AutoLoginUser", "user1"); 
regedit.regDeleteKeyValue("HKCU", "Software/Valve/Steam", "AutoLoginUser");

regedit.regWriteKey("HKCU", "Software/Valve/Steam");
regedit.regDeleteKeyIncludingSubkeys("HKCU", "Software/Valve/Steam");

//Util
const exists = regedit.regKeyExists("HKCU", "Software/Valve");
const subkeys = regedit.regListAllSubkeys("HKCU", "Software/Valve");
const values = regedit.regListAllValues("HKCU", "Software/Valve/Steam");
const type = regedit.regQueryValueType("HKCU", "Software/Valve/Steam", "AutoLoginUser");

//Import/Export
const dump = regedit.regExportKey("HKCU", "Software/Valve/Steam");
regedit.regImportKey("HKCU", "Software/Valve/SteamBackup", dump);

Install

npm install regodit

API

⚠️ This module is only available as an ECMAScript module (ESM) starting with version 2.0.0. Previous version(s) are CommonJS (CJS) with an ESM wrapper.

💡 Promises are under the promises namespace.

import * as regedit from "regodit";
regedit.promises.regListAllSubkeys("HKCU","Software/Valve") //Promise
regedit.regListAllSubkeys("HKCU","Software/Valve") //Sync

import * as regedit from "regodit/promises";
regedit.regListAllSubkeys("HKCU","Software/Valve") //Promise

✔️ root key accepted values are "HKCR", "HKCU", "HKLM", "HKU" or "HKCC".

Named export

regKeyExists(root: string, key: string): boolean

If the key exists or not.

regQueryValueType(root: string, key: string, name: string): string

Return key/name type:

  • NONE
  • SZ
  • EXPAND_SZ
  • BINARY
  • DWORD
  • DWORD_BIG_ENDIAN
  • LINK
  • MULTI_SZ
  • RESOURCE_LIST
  • FULL_RESOURCE_DESCRIPTOR
  • RESOURCE_REQUIREMENTS_LIST
  • QWORD

Return "NONE" If the key doesn't exist or is of an unknown type.

regQueryStringValue(root: string, key: string, name: string): string | null

Return string value of given key/name. Return null If the key/name doesn't exist.

⚠️ Supported: REG_SZ & REG_EXPAND_SZ

regQueryMultiStringValue(root: string, key: string, name: string): string[] | null

Return string values of given key/name. Return null If the key/name doesn't exist.

⚠️ Supported: REG_MULTI_SZ

regQueryStringValueAndExpand(root: string, key: string, name: string): string | null

Return string value of given key/name and expand any environment-variable by replacing them with the value defined for the current user.

//Non-Expanded
regQueryStringValue("HKCU","Software/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders", "AppData")
//"%USERPROFILE%\AppData\Roaming"

//Expanded
regQueryStringValueAndExpand("HKCU","Software/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders", "AppData")
//"C:\Users\Xan\AppData\Roaming"

Return null If the key/name doesn't exist.

⚠️ Supported: REG_EXPAND_SZ

regQueryBinaryValue(root: string, key: string, name: string): Buffer | null

Return binary value of given key/name. Return null If the key/name doesn't exist.

⚠️ Supported: REG_BINARY

regQueryIntegerValue(root: string, key: string, name: string): number | bigint | null

Return integer value of given key/name.

NB: REG_QWORD is a 64-bit unsigned integer. Return a bigint instead of a number if integer value > Number.MAX_SAFE_INTEGER

Return null If the key/name doesn't exist.

⚠️ Supported: REG_DWORD & REG_QWORD

regWriteKey(root: string, key: string): void

Create given key whether the key already exists or not (subkeys are created if necessary).

regWriteStringValue(root: string, key: string, name: string, value: string): void

Write string value in given key/name as 'REG_SZ' (subkeys are created if necessary).

regWriteMultiStringValue(root: string, key: string, name: string, value: string[]): void

Write string values in given key/name as 'REG_MULTI_SZ' (subkeys are created if necessary).

regWriteExpandStringValue(root: string, key: string, name: string, value: string): void

Write string value in given key/name as 'REG_EXPAND_SZ' (subkeys are created if necessary).

regWriteBinaryValue(root: string, key: string, name: string, value: Buffer): void

Write binary value in given key/name as 'REG_BINARY' (subkeys are created if necessary).

regWriteDwordValue(root: string, key: string, name: string, value: number | bigint): void

Write integer value in given key/name as 'REG_DWORD' (subkeys are created if necessary).

regWriteQwordValue(root: string, key: string, name: string, value: number | bigint): void

Write integer value in given key/name as 'REG_QWORD' (subkeys are created if necessary).

regDeleteKeyValue(root: string, key: string, name: string): void

Delete value in given key.

regDeleteKey(root: string, key: string): void

Delete given key. NB: If the key has some subkeys then deletion will be aborted (Use RegDeleteKeyIncludingSubkeys below instead)

regDeleteKeyIncludingSubkeys(root: string, key: string): void

Delete given key and all its subkeys.

⚠️ The sync version could throw with RangeError: Maximum call stack size exceeded when used with a big tree; consider using the promise version in such case.

regListAllSubkeys(root: string, key: string): string[] | []

List all subkeys name for a given key (non-recursive). NB: For a more complete listing see RegExportKey below.

const result = regListAllSubkeys("HKCU","Software/Valve/Steam");
console.log(result);
/*
[
  "ActiveProcess",
  "Apps",
  "steamglobal"
  "Users"
]
*/

Return an empty array If the key doesn't exist or has no subkeys.

regListAllValues(root: string, key: string): string[] | []

List all values name for a given key. NB: For a more complete listing see RegExportKey below.

const result = regListAllValues("HKCU","Software/Valve/Steam");
console.log(result);
/*
[
  "AlreadyRetriedOfflineMode",
  "AutoLoginUser",
  "BigPictureInForeground",
  "DPIScaling",
  ...
]
*/

Return an empty array If the key doesn't exist or has no values.

regExportKey(root: string, key: string, option?: object): object

List all values with their name, content, type and all subkeys. Exported in an object representation where subkeys are treated as nested objects and values stored in the property symbol "values".

option ⚙️

|name|type|default|description| |----|----|-------|------------| |recursive|boolean|true|List values of subkeys|

Example:

const dump = await regExportKey("HKCU","Software/Valve/Steam");
console.dir(dump, { depth: null });

Output:

{
  [Symbol(values)]: [
    {"name": "H264HWAccel", "type": "DWORD", "data": 1},
    {"name": "Language", "type": "SZ", "data": "english"},
    // etc...
   ],
   "ActiveProcess": {
    [Symbol(values)]: [
      {"name": "SteamClientDll", "type": "SZ", "data": "steamclient.dll"},
      {"name": "SteamClientDll64", "type": "SZ", "data": "steamclient64.dll"},
      // etc...
    ]
   },
  "Apps": { 
    [Symbol(values)]: [],
    "480": {
      [Symbol(values)]: [
        {"name": "Name", "type": "SZ", "data": "Spacewar"}, 
        // etc...
      ]
    },
    "550": {
      [Symbol(values)]: [
        {"name": "Installed", "type": "DWORD", "data": 0},
        {"name": "Name", "type": "SZ", "data": "Left 4 Dead 2"},
        // etc...
      ]
    },
    // etc...
  },
  // etc...
}

regImportKey(root: string, key: string, data: object, option?: object): void

Import back to the registry a previously exported key dump (see RegExportKey). This overwrites existing data if any.

option ⚙️

|name|type|default|description| |----|----|-------|-----------| |purgeDest|boolean|false|Delete target key and its subkeys before importing|

Build cgo-dll

⚠️ CGO requires a cross compiling C compiler for the target architecture.

  • GoLang 1.21.4 windows/amd64
  • Zig 0.11.0 as the C cross compiler and it should be added to your environment variable PATH

Run:

  • npm run build:win (win32/powershell)
  • npm run build:win:legacy (win32/cmd)
  • npm run build:linux (linux/bash)

Targets:

  • Windows
    • x86
    • x64
    • arm64

Compiled DLLs can be found in the ./dist folder.