• Stars
    star
    270
  • Rank 148,610 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host

regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host.

No pesky native code :-)

Install

npm install regedit

Example

const regedit = require('regedit').promisified

async function main() {
  const listResult = await regedit.list('HKCU\\SOFTWARE')
  console.log(listResult)

  await regedit.createKey(['HKLM\\SOFTWARE\\MyApp2', 'HKCU\\SOFTWARE\\MyApp'])
  await regedit.putValue({
    'HKCU\\SOFTWARE\\MyApp': {
        Company: {
            value: 'Moo corp',
            type: 'REG_SZ'
        }
    },
    'HKLM\\SOFTWARE\\MyApp2': { 
      test: {
        value: '123',
        type: 'REG_SZ'
      } 
    }
  })
}

main()

Friendly warning regarding 32bit and 64bit OS / Process

When launching a 32bit application in 64bit environment, some of your paths will be relative to wow6432node. Things might get a little unexpected if you try to find something you thought was in HKLM\Software when in fact it is located at HKLM\Software\wow6432node. To overcome this the arch methods were added.

Further reading here

A note about Electron

This software uses Windows Script Host to read and write to the registry. For that purpose, it will execute .wsf files. When packaging the app's dependencies with ASAR, node-regedit will not be able to access the windows script files, because they are bundled in a single ASAR file. Therefore it is necessary to store the .wsf files elsewhere, outside of the packaged asar file. You can set your custom location for the files with setExternalVBSLocation(location):

callbacks and promise based APIs

regedit was originally written using callbacks, but a promise based API was added later:

// callback api
const regedit = require('regedit')
// promise api
const promisifiedRegedit = require('regedit').promisified
// Assuming the files lie in <app>/resources/my-location
const vbsDirectory = path.join(path.dirname(electron.remote.app.getPath('exe')), './resources/my-location');
regedit.setExternalVBSLocation(vbsDirectory);

Also, take a look at #60

API

Every command executes a sub process that runs vbscript code. To boost efficiency, every command supports batching.

Reading keys and values

regedit.list([String|Array], [Function])

Lists the direct content of one or more sub keys. Specify an array instead of a string to query multiple keys in the same run.

Given the command:

regedit.list(['HKCU\\SOFTWARE', 'HKLM\\SOFTWARE', 'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST'], function(err, result) {
    ...
})

Result will be an object with the following structure:

{
    'HKCU\\SOFTWARE': {
        exists: true,
        keys: [ 'Google', 'Microsoft', ... more direct sub keys ]
        values: {
            'valueName': {
                value: '123',
                type: 'REG_SZ'
            }
            ... more direct child values of HKCU\\SOFTWARE
        }
    },
    'HKLM\\SOFTWARE': {
        exists: true,
        keys: [ 'Google', 'Microsoft', ... more direct sub keys ]
        values: {
            'valueName': {
                value: '123',
                type: 'REG_SZ'
            }
            ... more direct child values of HKLM\\SOFTWARE
        }
    },
    'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST': {
        exists: false,
        keys: [],
        values: {}
    }
}
Note about listing default values

In the windows registry a key may have a default value. When enumarting value names, the default value's name will be empty. This presents a minor problem when including the empty value in a set with other values since it cannot be safely named with anything but the empty string, for fear of collision with other values.

Thus, accessing the default value becomes slightly awkward:

regedit.list('path\\to\\default\\value', function (err, result) {
    var defaultValue = result['path\\to\\default\\value'].values[''].value
})

For now this is how its going to be, but in the future this will probably change, possibly in a way that will effect the whole interface.

list with callback api will be deperecated and eventually removed in future versions, take a look at the streaming interface below

regedit.list([String|Array]) - streaming interface

Same as regedit.list([String|Array], [Function]) exposes a streaming interface instead of a callback. This is useful for situations where you have a lot of data coming in and out of the list process. Using the streaming interface is also important when trying to fetch a large amount of keys from the registry, as it overcomes the limitation of passing data as a command line argument.

This operation will mutate the keys array

Example:

regedit.list(['HKCU\\SOFTWARE', 'HKLM\\SOFTWARE'])
.on('data', function(entry) {
    console.log(entry.key)
    console.log(entry.data)
})
.on('finish', function () {
    console.log('list operation finished')
})

This code output will look like this:

HKCU\\SOFTWARE
{
    keys: [ 'Google', 'Microsoft', ... more direct sub keys ]
    values: {
        'valueName': {
            value: '123',
            type: 'REG_SZ'
        }
        ... more direct child values of HKCU\\SOFTWARE
    }
}
HKLM\\SOFTWARE
{
    keys: [ 'Google', 'Microsoft', ... more direct sub keys ]
    values: {
        'valueName': {
            value: '123',
            type: 'REG_SZ'
        }
        ... more direct child values of HKLM\\SOFTWARE    
    }
}

regedit.arch.list32([String|Array], [Function])

same as regedit.list([String|Array], [Function]), only force a 32bit architecture on the registry

regedit.arch.list32([String|Array])

streaming interface, see regedit.list([String|Array])

regedit.arch.list64([String|Array], [Function])

same as list, only force a 64bit architecture on the registry

regedit.arch.list64([String|Array])

streaming interface, see regedit.list([String|Array])

regedit.arch.list([String|Array], [Function])

same as list, only force your system architecture on the registry (select automatically between list64 and list32)

regedit.arch.list([String|Array])

streaming interface, see regedit.list([String|Array])

regedit.listUnexpandedValues([String|Array], [function])

Lists the values of one or more value keys (or paths as I like to call them) without expanding any embedded environment variables. Specify an array instead of a string to query multiple keys in the same run.

Read issue #40 on why and when this is needed.

Unlike the rest of this project, which is based on StdRegServ, this API (added on May 2022) uses a wshell object RegRead method. Although it's properly tested, please report any issues asap.

const regedit = require('./index').promisified

async function main() {
  const res = await regedit.listUnexpandedValues('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData')

  console.log(JSON.stringify(res, null, '\t'))
}

main()

Result will look like this:

[
  {
    "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData",
    "exists": true,
    "value": "%USERPROFILE%\\AppData\\Roaming"
  }
]

This API also support a streaming interface much like list does.

Manipulating the registry

regedit.createKey([String|Array], [Function])

Creates one or more keys in the registry This operation will mutate the keys array

regedit.deleteKey([String|Array], [Function])

Deletes one or more keys in the registry This operation will mutate the keys array

regedit.putValue(Object, Function)

Put one or more values in the registry. The Object given to this function is almost identical to the result of regedit.list().

Here is an example:

var valuesToPut = {
    'HKCU\\Software\\MySoftware': {
        'myValue1': {
            value: [1,2,3],
            type: 'REG_BINARY'
        },
        'myValue2': {
            value: 'aString',
            type: 'REG_SZ'
        }
    },
    'HKCU\\Software\\MySoftware\\foo': {
        'myValue3': {
            value: ['a', 'b', 'c']
            type: 'REG_MULTI_SZ'
        }
    }
}

regedit.putValue(valuesToPut, function(err) {

})

Supported value types are:

  • REG_SZ, REG_EXPAND_SZ: a string basically
  • REG_DWORD, REG_QWORD: should use javascript numbers
  • REG_MULTI_SZ: an array of strings
  • REG_BINARY: an array of numbers (representing bytes)
  • REG_DEFAULT: see note about default values below
Note about setting default values

When including a default value in a putValue operation, one must use the REG_DEFAULT type. Further more, the name of the value is insignificant since in the registry the default value has no name, but because of the way the node and the vb processes communicate a name must be used. Please note that the only legal value type of a default value is REG_SZ

this is a temporary solution and is subject to change in future versions

var values = {
    'HKCU\\Software\\MySoftware': {
        'someNameIDontCareAbout': {
            value: 'Must be a string',
            type: 'REG_DEFAULT'
        },
        'myValue2': {
            value: 'aString',
            type: 'REG_SZ'
        }
    }
}
regedit.putValue(values, function (err) {    
})

For now this is how its going to be, but in the future this will probably change, possibly in a way that will effect the whole interface.

regedit.deleteValue([String|Array], [Function])

Deletes one or more values in the registry This operation will mutate the keys array

Promises

To use promises access the function you want through regedit.promisified, all function signatures are the same ([String|Array], [Arch (optional)])

Default arch is agnostic.

Example: regedit.promisified.list([String|Array], [Arch (optional)])

try {
    const registryList = await regedit.promisified.list(['HKCU\\SOFTWARE', 'HKLM\\SOFTWARE', 'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST'])
} catch (e) {
    console.log('Error while listing keys:', e.message)
}

Result and errors should be the same as not promisified.

Develop

Run tests

    mocha -R spec

Enable debug output

    set DEBUG=regedit

TODO

None :)

More Repositories

1

node-bcat

A pipe to browser utility
JavaScript
338
star
2

license-report

create a short report about a project's dependencies (license, url etc)
JavaScript
218
star
3

nw-ninja

A minimalistic NW.js starter project for ninjas
JavaScript
97
star
4

node-loadbalance

A collection of distilled load balancing engines
JavaScript
81
star
5

tempus-fugit

A scheduling and time utilities module that doesn't waste your time
JavaScript
70
star
6

find-port

finds an open port
JavaScript
60
star
7

node-hcat

pipe html into your browser from command line
JavaScript
48
star
8

node-dynamic-middleware

turn a connect/express middleware into a runtime replaceable, deletable middleware
JavaScript
43
star
9

qool

Qool, a leveldb backed Queue
JavaScript
42
star
10

pickpick

An A/B testing engine
JavaScript
37
star
11

catchart

Pipe something from command line to a chart in the browser
JavaScript
34
star
12

node-octofications

github feed as notifications in your desktop
JavaScript
30
star
13

redis-cluster

[DISCONTINUED] a hashring based redis cluster
JavaScript
24
star
14

darkmagic

An experimental opinionated dependency injection module
JavaScript
21
star
15

node-quick-serve

quickly start an http download server and serve a single file or a directory from command line
JavaScript
19
star
16

pluggage

A very slim framework for building pluggable code.
JavaScript
18
star
17

remote-css-select-stream

Quickly run a css selector against a remote page source from a program or cli
JavaScript
17
star
18

redshift-cli

command line for querying and managing a redshift cluster
JavaScript
15
star
19

node-digital-tree

Trie data structure
JavaScript
14
star
20

galaxya

embeddable peer 2 peer service discovery and configuration
JavaScript
13
star
21

node-loadbalance-middleware

A middleware that load balance requests between several other middlewares
JavaScript
12
star
22

node-xn

a distilled engine for creating RPC Servers/Clients
JavaScript
9
star
23

simply-wait

Simply wait for some async things to happen.
JavaScript
8
star
24

blog-automate-nwjs-ui-testing

the code for this: http://blog.yanivkessler.com/2015/03/21/automate-nwjs-ui-testing/ blog post
JavaScript
8
star
25

node-k-pipeline

Executes a bunch of callback styled functions serially
JavaScript
7
star
26

node-json-explorer

explore json objects in your browser
JavaScript
7
star
27

exponential-backoff

Opinionated exponential backoff retry driver
JavaScript
6
star
28

forkraft

a helper library for cluster api
JavaScript
6
star
29

db-stuff

db stuff
JavaScript
5
star
30

cluster-file-writer

write to a single file from all workers in your cluster
JavaScript
5
star
31

websql-sugar

something to make web sql sweeter
JavaScript
4
star
32

node-yalla

A minimalistic logging lib
JavaScript
4
star
33

node-hstacks

Build hierarchies of stacks of middlewares
JavaScript
4
star
34

node-sinopia-leveldb

a leveldb backed auth plugin for sinopia private npm
JavaScript
4
star
35

osx-notify

A osx only bash/applescript that creates a notification when a process is finished
Shell
4
star
36

pickpick-targeting-compiler

compiles targeting expressions to javascript code for pickpick engine
JavaScript
4
star
37

node-assist

a personal AI assistant
JavaScript
4
star
38

node-vhosts

A cli based vhosts server for express/connect apps
JavaScript
4
star
39

id-generator

generate unique ids
JavaScript
4
star
40

pg-schema

create a schema object by querying the metadata tables of postgresql/redshift
JavaScript
4
star
41

insert-sql-generator

create generic sql insert queries from javascript objects
JavaScript
3
star
42

s3shield

a small abstraction over several s3 providers
JavaScript
3
star
43

connect-crypto

some crypto related middlewares for connect
JavaScript
3
star
44

catgraph

pipe graph data to the browser
JavaScript
3
star
45

tokenize

personal tokenize util
JavaScript
3
star
46

node-embedding

JavaScript
3
star
47

fuzzy-math

fuzzy sets, fuzzy numbers, fuzzy fuzzy fuzzy...
JavaScript
3
star
48

serverless-onehook

one hook to rule them all
JavaScript
2
star
49

herbal

duplicate data into several streams
JavaScript
2
star
50

repl

a personal lib for building repls
JavaScript
2
star
51

maxmind-download

download maxmind databases
JavaScript
2
star
52

classgen

JavaScript
2
star
53

node-k-together

Executes a bunch of callback styled functions in parallel
JavaScript
2
star
54

isos

test the current OS // isOs('windows'), isOs('linux')
JavaScript
2
star
55

node-nmg

(my) Node Module Generator
JavaScript
2
star
56

node-async-map-limit

like Promise.all() but with limit on concurrency
JavaScript
1
star
57

monitor-url-tool

simple url monitoring tool
JavaScript
1
star
58

directory-watcher

JavaScript
1
star
59

spawn-child-process-problem

spawn-child-process-problem
JavaScript
1
star
60

schedule-aws-lambda

attach a schedule to an existing aws lambda function
JavaScript
1
star
61

node-command-queue

A command queue
JavaScript
1
star
62

ec2-util

a bunch of ec2 related utilities
JavaScript
1
star
63

digital-chain

A linked list implementation
JavaScript
1
star
64

netee

tee(1) for network traffic. duplicate traffic to several backends, reply from one
JavaScript
1
star
65

node-local-update-server

A tool that creates a local update server
JavaScript
1
star
66

darkmagic-dispel

JavaScript
1
star
67

node-csv-splitter

JavaScript
1
star
68

node-json

JavaScript
1
star
69

emitter-sniffer

takes an event emitter instance and print all events when they are fired
1
star
70

node-file-index

quickly create an in memory index of files and their content
JavaScript
1
star
71

parse-arguments

parse command line style positional and named arguments, eg. `cmd positional --name=foo`
JavaScript
1
star
72

simple-file-writer

write to a file, manage back pressure and buffering
JavaScript
1
star
73

node-search

JavaScript
1
star