All Projects → CatalystCode → windows-registry-node

CatalystCode / windows-registry-node

Licence: MIT license
Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and other goodies.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to windows-registry-node

React Ckeditor
CKEditor component for React with plugin and custom event listeners support
Stars: ✭ 124 (+18.1%)
Mutual labels:  npm-module
Darkmode.js
🌓 Add a dark-mode / night-mode to your website in a few seconds
Stars: ✭ 2,339 (+2127.62%)
Mutual labels:  npm-module
pwainit
Turn your existing website to Progressive Web App or Initiate PWA project using single command!!. 'npm i -g pwainit' to install pwainit and get started 🚀
Stars: ✭ 45 (-57.14%)
Mutual labels:  npm-module
React Native Color Wheel
🌈 A react native reusable and color picker wheel
Stars: ✭ 137 (+30.48%)
Mutual labels:  npm-module
Reactopt
A CLI React performance optimization tool that identifies potential unnecessary re-rendering
Stars: ✭ 1,975 (+1780.95%)
Mutual labels:  npm-module
Abort Controller
An implementation of WHATWG AbortController interface.
Stars: ✭ 213 (+102.86%)
Mutual labels:  npm-module
Discord.js Musicbot Addon
This DOES NOT WORK any more. This repo only serves as an archive for is anyone wants to pickup my work. You may still join the discord however.
Stars: ✭ 109 (+3.81%)
Mutual labels:  npm-module
simple-load-script
Very simple promise based script loader and JSONP
Stars: ✭ 13 (-87.62%)
Mutual labels:  npm-module
Node Regedit
Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
Stars: ✭ 178 (+69.52%)
Mutual labels:  npm-module
Singlespotify
🎵 Create Spotify playlists based on one artist through the command line
Stars: ✭ 254 (+141.9%)
Mutual labels:  npm-module
Tanam
Plug-n-play CMS for websites on Firebase
Stars: ✭ 139 (+32.38%)
Mutual labels:  npm-module
Cerebral
Declarative state and side effects management for popular JavaScript frameworks
Stars: ✭ 1,946 (+1753.33%)
Mutual labels:  npm-module
Eslint Plugin Eslint Comments
Additional ESLint rules for directive comments of ESLint.
Stars: ✭ 221 (+110.48%)
Mutual labels:  npm-module
Zoom
Javascript library to do pinch zoom that preserves scale and rotation correctly.
Stars: ✭ 130 (+23.81%)
Mutual labels:  npm-module
ifto
A simple debugging module for AWS Lambda (λ) timeout
Stars: ✭ 72 (-31.43%)
Mutual labels:  npm-module
Tspath
TypeScript path alias resolver
Stars: ✭ 115 (+9.52%)
Mutual labels:  npm-module
Jsonexport
{} → 📄 it's easy to convert JSON to CSV
Stars: ✭ 208 (+98.1%)
Mutual labels:  npm-module
eslint-plugin-gridsome
ESLint plugin for Gridsome
Stars: ✭ 45 (-57.14%)
Mutual labels:  npm-module
fetch-action-creator
Fetches using standardized, four-part asynchronous actions for redux-thunk.
Stars: ✭ 28 (-73.33%)
Mutual labels:  npm-module
Ts ci
✅ Continuous integration setup for TypeScript projects via GitHub Actions.
Stars: ✭ 225 (+114.29%)
Mutual labels:  npm-module

windows-registry-node

Build status

Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and launch processes as an Administrator.

Install

This library interacts with native Windows APIs. To add this module to your Node application, install the package:

npm install windows-registry

To install node modules that require compilation on Windows, make sure you have installed the necessary build tools. Specifically, we need npm install -g node-gyp, a cross-platform cli written in Node.js for native addon modules for Node.js.

To install node-gyp, install python v2.7.3 and Visual Studio 2013 build tools. You do not need to install the full Visual Studio, only the build tools are required. Once the build tools are installed, you should be able to do npm install -g node-gyp.

Creating File Associations

To create a file association, you can call the fileAssociation.associateExeForFile API, which will make windows assign a default program for an arbitrary file extension:

var utils = require('windows-registry').utils;
utils.associateExeForFile('myTestHandler', 'A test handler for unit tests', 'C:\\path\\to\\icon', 'C:\\Program Files\\nodejs\\node.exe %1', '.zzz');

After running the code above, you will see files with the extension of .zzz will be automatically associated with the Node program and their file icon will be changed to the Node file icon.

'GIF showing file association'

Reading and Writing to the Windows Registry

This library implements only a few of the basic registry commands, which allow you to do basic CRUD operations for keys in the registry.

Opening a Registry Key

Registry keys can be opened by either opening a predefined registry key defined in the windef module:

var Key = require('windows-registry').Key;
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);

Or you can open a sub key from an already opened key:

var Key = require('windows-registry').Key;
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);

And don't forget to close your key when you're done. Otherwise, you will leak native resources:

key.close();

Creating a Key

Creating a key just requires that you have a Key object by either using the predefined keys within the windef.HKEY or opening a subkey from an existing key.

var Key = require('windows-registry').Key;
// predefined key
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var createdKey = key.createSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);

Deleting a Key

To delete a key just call the Key.deleteKey() function.

createdKey.deleteKey();

Writing a Value to a Key

To write a value, you will again need a Key object and just need to call the Key.setValue function:

var Key = require('windows-registry').Key,
	windef = require('windows-registry').windef;

var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
key.setValue('test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');

Get a Value From a Key

To get a value from a key, just call Key.getValue:

var value = key.getValue('test_value_name');

The return value depends on the type of the key (REG_SZ for example will give you a string).

Launching a Process as an Admin

To launch a process as an Administrator, you can call the utils.elevate API, which will launch a process as an Administrator causing the UAC (User Account Control) elevation prompt to appear if required. This is similar to the Windows Explorer command "Run as administrator". Pass in FILEPATH to the process you want to elevate. Pass in anyPARAMETERS to run with the process. Since this is an asynchronous call, pass in a callback to handle user's selection.

var utils = require('windows-registry').utils;
utils.elevate('C:\\Program Files\\nodejs\\node.exe', 'index.js', function (err, result){console.log(result);});

The process you want to launch with admin access will only be launched after the callback is called and only if the user clicks Yes in the UAC prompt. Otherwise, the process will not be launched. If the user is already running as an admin, the UAC prompt will not be triggered and the process you provided will be launched as an administrator automatically.

'GIF showing launch process as an admin'

More Docs?

Make your way over to the tests section to see how the module can be used.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].