Titanium JIRA Archive
Appcelerator Daemon (DAEMON)

[DAEMON-81] winreglib: Implement native addon to watch Windows Registry keys

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusResolved
ResolutionFixed
Resolution Date2019-05-24T20:00:11.000+0000
Affected Version/sn/a
Fix Version/sAppc Daemon 2.3.0
Componentswinreglib
Labelsn/a
ReporterChris Barber
AssigneeChris Barber
Created2017-05-09T15:02:50.000+0000
Updated2019-06-04T16:07:33.000+0000

Description

On Windows, the daemon needs to watch the Windows Registry for Android SDK, JDK, and Visual Studio related keys so that the system info can monitor it. In the daemon prototype, the detect engine would use https://www.npmjs.com/package/winreg (which calls reg.exe) and polls the Windows Registry every 15 seconds. This is inefficient and slow. It would be better if we had a native C++ addon for Node that we could use. It looks like it would need to call RegNotifyChangeKeyValue() (https://msdn.microsoft.com/en-us/library/windows/desktop/ms724892(v=vs.85).aspx). The C++ code would expose a simple API where you can start and stop watching a specific key. Then we need a high-level .js API that exports a nicer, efficient ES6 compliant API. I imagine the RegistryWatcher would extend an EventEmitter. This file would also make use of https://www.npmjs.com/package/node-pre-gyp-init to try and downloading the pre-built binary.

API

The public API will expose 3 methods: get, list, and watch. get() will retrieve the value for a given key. list() will retrieve all subkeys and values for a given key. watch() will start watching a registry key for changes. It will return a watch handle that emits change events and also contains the stop() method to unwatch.
import { get, list, watch } from 'winreglib';

const value = get('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run');
console.log(value = ${value});

const { resolvedRoot, key, subkeys, values } = list('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run');
console.log(resolvedRoot = ${resolvedRoot});
console.log(key = ${key});
console.log('subkeys:', subkeys);
console.log('values:', values);

const handle = watch('HKCU'\\Software\\Microsoft\\Windows\\CurrentVersion\\Run');
handle.on('change', evt => {
    console.log('change!', evt);

    handle.stop();
});

Comments

  1. Chris Barber 2019-05-24

    Published v1.0.0: https://www.npmjs.com/package/winreglib. Opted to use [prebuildify](https://www.npmjs.com/package/prebuildify) and [node-gyp-build](https://www.npmjs.com/package/node-gyp-build) instead of [node-pre-gyp](https://www.npmjs.com/package/node-pre-gyp) and [node-pre-gyp-init](https://www.npmjs.com/package/node-pre-gyp-init). The builds are pre-compiled before publish and included in the package. There is no need for S3 or Github to store the prebuilt binaries. Because winreglib uses N-API, version 3, there shouldn't be any issues with future Node.js release and thus no need for runtime downloading of the prebuild or compiling the module. The package contains prebuilds for 64-bit and 32-bit.

JSON Source