Skip to content

Commit c81ca44

Browse files
committed
Update README.md to provide more installation guide and examples
1 parent a23daab commit c81ca44

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

README.md

+33-16
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,38 @@
22

33
[![Build status](https://ci.appveyor.com/api/projects/status/ot69wbkyrcv7ig3p/branch/master?svg=true)](https://ci.appveyor.com/project/sedouard/windows-registry-node/branch/master)
44

5-
Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and other goodies & such. You can also enable your application to run processes as an Administrator.
5+
Read and Write to the Windows registry in-process from Node.js. Easily set application file associations and launch processes as an Administrator.
66

77
## Install
88

9-
This library interacts with native Windows APIs. Ensure you have Visual Studio 2013 or newer build tools. Using Visual Studio is not
10-
required. Then install the package:
9+
This library interacts with native Windows APIs. To add this module to your Node application, install the package:
1110

1211
```
1312
npm install windows-registry-node
13+
1414
```
1515

16+
To install node modules that require compilation on Windows, make sure you have installed the [necessary build tools](https://github.com/nodejs/node-gyp#installation). Specifically, we need `npm install -g node-gyp`, a cross-platform cli written in Node.js for native addon modules for Node.js.
17+
18+
To install `node-gyp`, install [python v2.7.3](http://www.python.org/download/releases/2.7.3#download) and [Visual Studio 2013 build tools](http://www.microsoft.com/en-gb/download/details.aspx?id=44914). You do not need to install the full Visual Studio, only the build tools are required. Once the build tools are installed, you should be able to do `npm install -g node-gyp`.
19+
1620
## Creating File Associations
1721

18-
To create a file association, you can call the `fileAssociation.associateExeForFile` api which will make windows assign a default program for
19-
an arbitrary file extension:
22+
To create a file association, you can call the `fileAssociation.associateExeForFile` API, which will make windows assign a default program for an arbitrary file extension:
2023

2124
```js
2225
var utils = require('windows-registry').utils;
2326
utils.associateExeForFile('myTestHandler', 'A test handler for unit tests', 'C:\\path\\to\\icon', 'C:\\Program Files\\nodejs\\node.exe %1', '.zzz');
27+
2428
```
25-
## Reading / Writing to the Windows Registry
29+
After running the code above, you will see files with the extension of `.zzz` will be automatically associated with the Node program and their file icon will be changed to the Node file icon.
30+
31+
!['GIF showing file association'](https://github.com/CatalystCode/windows-registry-node/blob/fix_readme/fileassoc.jpg)
32+
33+
## Reading and Writing to the Windows Registry
2634

2735
This library implements only a few of the basic registry commands, which allow you to do basic CRUD
28-
operations for keys to the registry.
36+
operations for keys in the registry.
2937

3038
### Opening a Registry Key
3139

@@ -34,6 +42,7 @@ Registry keys can be opened by either opening a predefined registry key defined
3442
```js
3543
var Key = require('windows-registry').Key;
3644
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
45+
3746
```
3847

3948
Or you can open a sub key from an already opened key:
@@ -42,12 +51,14 @@ Or you can open a sub key from an already opened key:
4251
var Key = require('windows-registry').Key;
4352
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
4453
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
54+
4555
```
4656

47-
And don't forget to close your key when you're done, otherwise, you'll leak native resources:
57+
And don't forget to close your key when you're done. Otherwise, you will leak native resources:
4858

4959
```js
5060
key.close();
61+
5162
```
5263

5364
### Creating a Key
@@ -59,26 +70,28 @@ var Key = require('windows-registry').Key;
5970
// predefined key
6071
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
6172
var createdKey = key.createSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
62-
```
6373

64-
### Delete a Key
74+
```
6575

76+
### Deleting a Key
6677
To delete a key just call the `Key.deleteKey()` function.
6778

6879
```js
6980
createdKey.deleteKey();
81+
7082
```
7183

72-
### Write a Value to a Key
84+
### Writing a Value to a Key
7385

74-
To write a value, you'll again need a [Key](lib/key.js) object and just need to call the `Key.setValue` function:
86+
To write a value, you will again need a [Key](lib/key.js) object and just need to call the `Key.setValue` function:
7587

7688
```js
7789
var Key = require('windows-registry').Key,
7890
windef = require('windows-registry').windef;
7991

8092
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
8193
key.setValue('test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');
94+
8295
```
8396

8497
### Get a Value From a Key
@@ -91,14 +104,18 @@ var value = key.getValue('test_value_name');
91104

92105
The return value depends on the type of the key (REG_SZ for example will give you a string).
93106

94-
## Launching a Process as An Admin
107+
## Launching a Process as an Admin
95108

96-
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.
109+
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 asynchronous call, pass in a callback to handle user's selection.
97110

98111
```js
99-
var uac = require('windows-registry').uac;
100-
uac.elevate('C:\\Program Files\\nodejs\\node.exe', 'index.js', function (err, result){console.log('callback');});
112+
var utils = require('windows-registry').utils;
113+
utils.elevate('C:\\Program Files\\nodejs\\node.exe', 'index.js', function (err, result){console.log(result);});
114+
101115
```
116+
The process you want to launch with admin access will only be launched after the callback is called and only if the user clicks Yes in the UAC prompt. Otherwise, the process will not be launched. If the user is already running as an admin, the UAC prompt will not be triggered and the process you provided will be launched as an administrator automatically.
117+
118+
!['GIF showing launch process as an admin'](https://github.com/CatalystCode/windows-registry-node/blob/fix_readme/elevate.gif)
102119

103120
## More Docs?
104121

elevate.gif

442 KB
Loading

fileassoc.jpg

12.6 KB
Loading

0 commit comments

Comments
 (0)