|
1 | 1 | # windows-registry-node
|
| 2 | + |
2 | 3 | Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and other goodies & such.
|
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +This library interacts with natvive Windows apis. Ensure you have Visual Studio 2013 or newer build tools. Using Visual Studio is not |
| 8 | +required. Then install the package: |
| 9 | + |
| 10 | +``` |
| 11 | +npm install windows-registry-node |
| 12 | +``` |
| 13 | + |
| 14 | +## Reading / Writing to the Windows Registry |
| 15 | + |
| 16 | +This library implements only a few of the basic registry commands, which allow you to do basic CRUD |
| 17 | +operations for keys to the registry. |
| 18 | + |
| 19 | +### Opening a Registry Key |
| 20 | + |
| 21 | +Registry keys can be opened by either opening a predefined registry key defined in the [windef](lib/windef.js) module: |
| 22 | + |
| 23 | +```js |
| 24 | +var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 25 | +``` |
| 26 | + |
| 27 | +Or you can open a sub key from an already opened key: |
| 28 | + |
| 29 | +```js |
| 30 | +var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 31 | +``` |
| 32 | + |
| 33 | +And don't forget to close your key when you're done, otherwise, you'll leak native resources: |
| 34 | + |
| 35 | +```js |
| 36 | +key.close(); |
| 37 | +``` |
| 38 | + |
| 39 | +### Creating a Key |
| 40 | + |
| 41 | +Creating a key just requires that you have a [Key](lib/key.js) object from either `registry.openKeyFromPredefined` or |
| 42 | +`registry.openKeyFromKeyObject`. |
| 43 | + |
| 44 | +```js |
| 45 | +var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 46 | +registry.createKey(key, '\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 47 | +``` |
| 48 | + |
| 49 | +### Delete a Key |
| 50 | + |
| 51 | +Similarly to creating a key you need a [Key](lib/key.js) object and you must specify the subkey name. |
| 52 | + |
| 53 | +```js |
| 54 | +registry.deleteKey(key, '\test_key_name'); |
| 55 | +``` |
| 56 | + |
| 57 | +### Write a Value to a Key |
| 58 | + |
| 59 | +To write a value, you'll again need a [Key](lib/key.js) object and just need to call the `registry.setValueForKeyObject` function: |
| 60 | + |
| 61 | +```js |
| 62 | +registry.setValueForKeyObject(key, 'test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value'); |
| 63 | +``` |
0 commit comments