UNPKG

3.82 kBMarkdownView Raw
1node-winreg
2===========
3
4node module that provides access to the Windows Registry through the REG commandline tool
5
6
7Installation
8------------
9
10```shell
11npm install winreg
12```
13
14
15Usage
16-----
17
18Let's start with an example. The code below lists the autostart programs of the current user.
19
20```javascript
21
22var Winreg = require('winreg')
23, regKey = new Winreg({
24 hive: Winreg.HKCU, // HKEY_CURRENT_USER
25 key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' // key containing autostart programs
26 })
27
28// list autostart programs
29regKey.values(function (err, items) {
30 if (err)
31 console.log('ERROR: '+err);
32 else
33 for (var i in items)
34 console.log('ITEM: '+items[i].name+'\t'+items[i].type+'\t'+items[i].value);
35});
36
37```
38
39
40The following options are processed by the Winreg constructor:
41
42 * __host__ the optional hostname, must start with the '\\\\' sequence
43 * __hive__ the optional hive id (see below), the default is __HKLM__
44 * __key__ the optional key, the default is th root key
45
46The key, if specified, has to start, but must not be terminated with a '\\' character.
47
48
49The instances of Winreg provide access to a single registry key. The hive id can be one of the following:
50
51 * __HKLM__ HKEY_LOCAL_MACHINE
52 * __HKCU__ HKEY_CURRENT_USER
53 * __HKCR__ HKEY_CLASSES_ROOT
54 * __HKCC__ HKEY_CURRENT_CONFIG
55 * __HKU__ HKEY_USERS
56
57
58Registry values are returned as objects, containing the following information:
59
60 * __host__ the hostname, if it has been set in the options
61 * __hive__ the hive id, as specified in the options
62 * __key__ the key, as specified in the options
63 * __name__ the name of the registry value
64 * __type__ one of the types listed below
65 * __value__ a string containing the value
66
67
68Registry values can have one of the following types:
69
70 * __REG_SZ__ a string value
71 * __REG_MULTI_SZ__ a multiline string value
72 * __REG_EXPAND_SZ__ an expandable string value
73 * __REG_DWORD__ a double word value (32 bit integer)
74 * __REG_QWORD__ a quad word value (64 bit integer)
75 * __REG_BINARY__ a binary value
76 * __REG_NONE__ a value of unknown type
77
78
79Following methods are provided by instances of Winreg:
80
81<table>
82 <tr>
83 <th>Method</th>
84 <th>Parameters</th>
85 <th>Description</th>
86 </tr>
87 <tr>
88 <td>values</td>
89 <td>callback</td>
90 <td>list the values under this key</td>
91 </tr>
92 <tr>
93 <td>keys</td>
94 <td>callback</td>
95 <td>list the subkeys of this key</td>
96 </tr>
97 <tr>
98 <td>get</td>
99 <td>name, callback</td>
100 <td>gets a value by it's name</td>
101 </tr>
102 <tr>
103 <td>set</td>
104 <td>name, type, value, callback</td>
105 <td>sets a value</td>
106 </tr>
107 <tr>
108 <td>remove</td>
109 <td>name, callback</td>
110 <td>remove the value with the given key</td>
111 </tr>
112 <tr>
113 <td>create</td>
114 <td>callback</td>
115 <td>create this key</td>
116 </tr>
117 <tr>
118 <td>erase</td>
119 <td>callback</td>
120 <td>remove this key</td>
121 </tr>
122</table>
123
124
125Following readonly properties are provided by instances of Winreg:
126
127<table>
128 <tr>
129 <th>Property</th>
130 <th>Type</th>
131 <th>Description</th>
132 </tr>
133 <tr>
134 <td>host</td>
135 <td>string</td>
136 <td>the hostname, if specified in the options</td>
137 </tr>
138 <tr>
139 <td>hive</td>
140 <td>string</td>
141 <td>the registry hive</td>
142 </tr>
143 <tr>
144 <td>key</td>
145 <td>string</td>
146 <td>the registry key</td>
147 </tr>
148 <tr>
149 <td>path</td>
150 <td>string</td>
151 <td>this key's path</td>
152 </tr>
153 <tr>
154 <td>parent</td>
155 <td>Winreg</td>
156 <td>a new Winreg instance initialized with the parent key</td>
157 </tr>
158</table>