You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-10
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,8 @@ To create a file association you can call the `fileAssociation.associateExeForFi
19
19
an arbitrary file extension:
20
20
21
21
```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');
23
24
```
24
25
## Reading / Writing to the Windows Registry
25
26
@@ -31,13 +32,15 @@ operations for keys to the registry.
31
32
Registry keys can be opened by either opening a predefined registry key defined in the [windef](lib/windef.js) module:
32
33
33
34
```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 =newKey(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
35
37
```
36
38
37
39
Or you can open a sub key from an already opened key:
38
40
39
41
```js
40
-
var key =registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
42
+
var key =newKey(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
43
+
var key2 =key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
41
44
```
42
45
43
46
And don't forget to close your key when you're done, otherwise, you'll leak native resources:
@@ -48,29 +51,41 @@ key.close();
48
51
49
52
### Creating a Key
50
53
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.
53
55
54
56
```js
57
+
// predefined key
55
58
var key =registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
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
+
74
89
## Launching a Process as An Admin
75
90
76
91
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
81
96
82
97
## More Docs?
83
98
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