Home > Web Front-end > JS Tutorial > Method sharing: Node.JS changes the Windows registry Regedit

Method sharing: Node.JS changes the Windows registry Regedit

巴扎黑
Release: 2017-08-21 10:08:21
Original
2637 people have browsed it

注册表是windows操作系统中的一个核心数据库,这里介绍一些通过node.js操作注册表的几种方法,感兴趣的朋友参考下吧

注册表是windows操作系统中的一个核心数据库,其中存放着各种参数,直接控制着windows的启动、硬件驱动程序的装载以及一些windows应用程序的运行,从而在整个系统中起着核心作用。这些作用包括了软、硬件的相关配置和状态信息,比如注册表中保存有应用程序和资源管理器外壳的初始条件、首选项和卸载数据等,联网计算机的整个系统的设置和各种许可,文件扩展名与应用程序的关联,硬件部件的描述、状态和属性,性能记录和其他底层的系统状态信息,以及其他数据等。

这里介绍一些通过node.js操作注册表的几种方法

方法一:通过childprocess调用reg命令

reg命令是Windows提供的,它可以添加、更改和显示注册表项中的注册表子项信息和值,通过命令行输入 REG /?  即可弹出命令提示


C:\Users\Administrator>REG /?
REG Operation [Parameter List]
 Operation [ QUERY  | ADD  | DELETE | COPY  |
        SAVE  | LOAD  | UNLOAD | RESTORE |
        COMPARE | EXPORT | IMPORT | FLAGS ]
Copy after login

返回代码: (除了 REG COMPARE)

0 - 成功
1 - 失败

要得到有关某个操作的帮助,请键入:


 REG Operation /?
Copy after login

例如:


REG QUERY /?
 REG ADD /?
 REG DELETE /?
 REG COPY /?
 REG SAVE /?
 REG RESTORE /?
 REG LOAD /?
 REG UNLOAD /?
 REG COMPARE /?
 REG EXPORT /?
 REG IMPORT /?
 REG FLAGS /?
Copy after login

通过child_process简单的封装即可调用上面的命令了:


var cp = require('child_process');
cp.exec("REG QUERY HKEY_CURRENT_USER\XXX",function(error,stdout,stderr) {
});
Copy after login

方法二:通过node-regedit模块

node-regedit模块本质上也是通过对child_process的封装实现的,示例代码如下:


var regedit = require('regedit')
regedit.list('HKCU\\SOFTWARE', function(err, result) {
  ...
})
regedit.putValue({
  'HKCU\\SOFTWARE\\MyApp': {
    'Company': {
      value: 'Moo corp',
      type: 'REG_SZ'
    },
    'Version': { ... }
  },
  'HKLM\\SOFTWARE\\MyApp2': { ... }
}, function(err) {
  ...
})
regedit.createKey(['HKLM\\SOFTWARE\\Moo', 'HKCU\\SOFTWARE\\Foo'], function(err) {
  ...
})
Copy after login

The above is the detailed content of Method sharing: Node.JS changes the Windows registry Regedit. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template