Skip to content

Commit 4451f70

Browse files
author
Steven Edouard
committed
Merge pull request #25 from CatalystCode/doc_readme_key
Update README.md
2 parents 9985f88 + 9694a82 commit 4451f70

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

README.md

+25-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ To create a file association you can call the `fileAssociation.associateExeForFi
1919
an arbitrary file extension:
2020

2121
```js
22-
fileAssociation.associateExeForFile('myTestHandler', 'A test handler for unit tests', 'C:\\path\\to\\icon', 'C:\\Program Files\\nodejs\\node.exe %1', '.zzz');
22+
var utils = require('windows-registry');
23+
utils.associateExeForFile('myTestHandler', 'A test handler for unit tests', 'C:\\path\\to\\icon', 'C:\\Program Files\\nodejs\\node.exe %1', '.zzz');
2324
```
2425
## Reading / Writing to the Windows Registry
2526

@@ -31,13 +32,15 @@ operations for keys to the registry.
3132
Registry keys can be opened by either opening a predefined registry key defined in the [windef](lib/windef.js) module:
3233

3334
```js
34-
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
35+
var Key = require('windows-registry').Key;
36+
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
3537
```
3638

3739
Or you can open a sub key from an already opened key:
3840

3941
```js
40-
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
42+
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
43+
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
4144
```
4245

4346
And don't forget to close your key when you're done, otherwise, you'll leak native resources:
@@ -48,29 +51,41 @@ key.close();
4851

4952
### Creating a Key
5053

51-
Creating a key just requires that you have a [Key](lib/key.js) object from either `registry.openKeyFromPredefined` or
52-
`registry.openKeyFromKeyObject`.
54+
Creating a key just requires that you have a [Key](lib/key.js) object by either using the [predefined keys](https://github.com/CatalystCode/windows-registry-node/blob/master/lib/windef.js#L27) within the `windef.HKEY` or opening a subkey from an existing key.
5355

5456
```js
57+
// predefined key
5558
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
56-
registry.createKey(key, '\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
59+
var createdKey = key.createSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
5760
```
5861

5962
### Delete a Key
6063

61-
Similarly to creating a key you need a [Key](lib/key.js) object and you must specify the subkey name.
64+
To delete a key just call the `Key.deleteKey()` function.
6265

6366
```js
64-
registry.deleteKey(key, '\test_key_name');
67+
createdKey.deleteKey();
6568
```
6669

6770
### Write a Value to a Key
6871

6972
To write a value, you'll again need a [Key](lib/key.js) object and just need to call the `registry.setValueForKeyObject` function:
7073

7174
```js
72-
registry.setValueForKeyObject(key, 'test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');
75+
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
76+
key.setValue('test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');
7377
```
78+
79+
### Get a Value From a Key
80+
81+
To get a value from a key, just call `Key.getValue`:
82+
83+
```js
84+
var value = key.getValue('test_value_name');
85+
```
86+
87+
The return value depends on the type of the key (REG_SZ for example will give you a string).
88+
7489
## Launching a Process as An Admin
7590

7691
To launch a process as an Administrator, you can call the `uac.elevate` api, which will launch a process as an Administrator causing the UAC (User Account Control) elevation prompt to appear if required. This is similar to the Windows Explorer command "Run as administrator". Pass in `FILEPATH` to the process you want to elevate. Pass in any`PARAMETERS` to run with the process. Since this is an asychronous call, pass in a callback to handle user's selection.
@@ -81,4 +96,4 @@ uac.elevate('C:\\Program Files\\nodejs\\node.exe', 'index.js', function (err, re
8196

8297
## More Docs?
8398

84-
Make your way over to the [tests section](test) to see how the module is used.
99+
Make your way over to the [tests section](test) to see how the module can be used.

0 commit comments

Comments
 (0)