The registry is a core database in the windows operating system.Which stores various parameters,Directly controls the startup of windows, the loading of hardware drivers, and the operation of some windows applications,Thus it plays a central role in the entire system.These functions include related configuration and status information of software and hardware.For example, the initial conditions, preferences, and uninstall data of application and explorer shells are stored in the registry.Settings and permissions for the entire system of networked computers,The association of the file extension with the application,Description, status, and attributes of hardware components,Performance records and other underlying system status information,And other data.

Here are some ways to manipulate the registry through node.js

Method 1:Call the reg command through childprocess

The reg command is provided by Windows. It can add, change, and display registry subkey information and values ​​in the registry key.Enter reg /?from the command line to bring up the command prompt

c:\ users \ administrator>reg /?
reg operation [parameter list]
 operation [query | add | delete | copy |
        save | load | unload | restore |
        compare | export | import | flags]

Return code:(except reg compare)



To get help on an operation,Please type:

reg operation /?


reg query /?
 reg add /?
 reg delete /?
 reg copy /?
 reg save /?
 reg restore /?
 reg load /?
 reg unload /?
 reg compare /?
 reg export /?
 reg import /?
 reg flags /?

The above command can be invoked through a simple wrapper of child_process:

var cp=require ("child_process");
cp.exec ("reg query hkey_current_user \ xxx", function (error, stdout, stderr) {

Method 2:Through the node-regedit module

The node-regedit module is also essentially implemented by encapsulating child_process.The sample code is as follows:

var regedit=require ("regedit")
regedit.list ("hkcu \\ software", function (err, result) {
regedit.putvalue ({
  "hkcu \\ software \\ myapp":{
      value:"moo corp",      type:"reg_sz"
    },    "version":{...}
  },  "hklm \\ software \\ myapp2":{...}
}, function (err) {
regedit.createkey (["hklm \\ software \\ moo", "hkcu \\ software \\ foo"], function (err) {

Project address:https://github.com/ironsource/node-regedit

to sum up

  • Previous The difference and usage of String and StringBuffer and StringBuilder in java
  • Next Android Programming AppWidgetProvider Usage Example
  • Trends