winreglib

2019-09-12

winreglib是什么

什么是winreglib,Windows Registry Utility Library

winreglib使用教程帮助文档

Windows Registry Utility Library

A library for querying and watching the Windows Registry.

Prerequisites

winreglibrequires N-API version 3 and the following Node.js versions:

  • v8.12.0 or newer
  • v10.2.0 or newer

Installation

npm install winreglib

Introduction

winreglibis a native Node.js addon for querying the Windows Registry. The API is synchronous.

Currently winreglibonly supports read operations. It can support write operations someday if need and time exists.

Example

import winreglib from 'winreglib';

const key = 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion';
const results = winreglib.list(key);

console.log(`${results.root}\\${results.path}`);

console.log('  Subkeys:');
for (const subkey of results.subkeys) {
    console.log(`    ${subkey}`);
}

console.log('  Values:');
for (const valueName of results.values) {
    console.log(`    ${valueName} = ${winreglib.get(key, valueName)}`);
}

API

get(key, valueName)

Get a value for the given key and value name.

ArgumentTypeDescription
keyStringThe key beginning with the root.
valueNameStringThe name of the value to get.

Returns a String, Number, Buffer, Array.<String>, or nulldepending on the value.

If keyor valueNameis not found, an Erroris thrown.

const value = winreglib.get('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion', 'ProgramFilesDir');

console.log(value);
C:\Program Files

list(key)

Retreives all subkeys and value names for a give key.

ArgumentTypeDescription
keyStringThe key beginning with the root.

Returns an Objectwith the resolved resolvedRoot(String), key(String), subkeys(Array[String]), and values(Array[String]).

If keyis not found, an Erroris thrown.

const result = winreglib.list('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup');

console.log(result);
{ resolvedRoot: 'HKEY_LOCAL_MACHINE',
  key: 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup',
  subkeys:
   [ 'DPI',
     'ImageServicingData',
     'OC Manager',
     'OOBE',
     'PnpLockdownFiles',
     'PnpResources',
     'State',
     'Sysprep',
     'SysPrepExternal',
     'WindowsFeatures' ],
  values: [ 'LogLevel', 'BootDir' ] }

watch(key)

Watches a key for changes in subkeys or values.

ArgumentTypeDescription
keyStringThe key beginning with the root.

Returns a handle (EventEmitter) that emits "change"events. Call handle.stop()to stop watching the key.

const handle = winreglib.watch('HKLM\\SOFTWARE');
handle.on('change', evt => {
    console.log(`Got change! type=${evt.type} key=${evt.key}`);
    handle.stop();
});

The "change"event object contains a change "type"and the affected "key".

Event TypeDescription
addThe keywas added.
changeA subkey or value was added, changed, deleted, or permissions modified, but we don't know exactly what.
deleteThe keywas deleted.

watch()can track keys that do not exist and when they are created, a change event will be emitted. You can watch the same key multiple times, however each returned handle is unique and you must call handle.stop()for each.

Due to limitations of the Win32 API, watch()is unable to determine what actually changed during a changeevent type. You will need to call list()and cache the subkeys and values, then call list()again when a change is emitted and compare the before and after.

Note that watch()does not support recursively watching for changes.

Advanced

Debug Logging

winreglibexposes an event emitter that emits debug log messages. This is intended to help debug issues under the hood. The average user will never need to use this, however it would be handy when filing a bug.

winreglib.on('log', msg => console.log(msg));

Alternatively, winreglibuses the amazing snooploggdebug logger where you simply set the SNOOPLOGGenvironment variable to winreglib(or *) and it will print the debug log to stdout.

License

This project is open source under the Apache Public License v2and is developed by Axway, Incand the community. Please read the LICENSEfile included in this distribution for more information.


上一篇:appcd-dispatcher
下一篇:appcd-response
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部