File: win32reg.html

package info (click to toggle)
erlang-doc-html 1%3A11.b.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,284 kB
  • ctags: 10,724
  • sloc: erlang: 505; ansic: 323; makefile: 62; perl: 61; sh: 45
file content (395 lines) | stat: -rw-r--r-- 11,720 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
  <TITLE>win32reg</TITLE>
  <SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
  <STYLE TYPE="text/css">
<!--
    .REFBODY     { margin-left: 13mm }
    .REFTYPES    { margin-left: 8mm }
-->
  </STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
  <IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>win32reg</H1>
</CENTER>

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
win32reg
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
win32reg provides access to the registry on Windows
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P><CODE>win32reg</CODE> provides read and write access to the
registry on Windows. It is essentially a port driver wrapped around the
Win32 API calls for accessing the registry.

<P>The registry is a hierarchical database, used to store various system
and software information in Windows. It is available in Windows 95 and
Windows NT. It contains installation data, and is updated by installers
and system programs. The Erlang installer updates the registry by adding
data that Erlang needs.

<P>The registry contains keys and values. Keys are like the directories
in a file system, they form a hierarchy. Values are like files, they have
a name and a value, and also a type.

<P>Paths to keys are left to right, with sub-keys to the right and backslash
between keys. (Remember that backslashes must be doubled in Erlang strings.)
Case is preserved but not significant.
Example: <CODE>&#34;\\hkey_local_machine\\software\\Ericsson\\Erlang\\5.0&#34;</CODE> is the key
for the installation data for the latest Erlang release.

<P>There are six entry points in the Windows registry, top level keys. They can be
abbreviated in the <CODE>win32reg</CODE> module as:

<PRE>
Abbrev.          Registry key
=======          ============      
hkcr             HKEY_CLASSES_ROOT
current_user     HKEY_CURRENT_USER
hkcu             HKEY_CURRENT_USER
local_machine    HKEY_LOCAL_MACHINE
hklm             HKEY_LOCAL_MACHINE
users            HKEY_USERS
hku              HKEY_USERS
current_config   HKEY_CURRENT_CONFIG
hkcc             HKEY_CURRENT_CONFIG
dyn_data         HKEY_DYN_DATA
hkdd             HKEY_DYN_DATA
    
</PRE>

<P>The key above could be written as <CODE>&#34;\\hklm\\software\\ericsson\\erlang\\5.0&#34;</CODE>.

<P>The <CODE>win32reg</CODE> module uses a current key. It works much like the
current directory. From the current key, values can be fetched, sub-keys
can be listed, and so on.

<P>Under a key, any number of named values can be stored. They have name, and
types, and data.

<P>Currently, the <CODE>win32reg</CODE> module supports storing only the following
types: REG_DWORD, which is an
integer, REG_SZ which is a string and REG_BINARY which is a binary.
Other types can be read, and will be returned as binaries.

<P>There is also a &#34;default&#34; value, which has the empty string as name. It is read and
written with the atom <CODE>default</CODE> instead of the name.

<P>Some registry values are stored as strings with references to environment variables,
e.g. <CODE>&#34;%SystemRoot%Windows&#34;</CODE>. <CODE>SystemRoot</CODE> is an environment variable, and should be
replaced with its value. A function <CODE>expand/1</CODE> is provided, so that environment
variables surrounded in % can be expanded to their values.

<P>For additional information on the Windows registry consult the Win32
Programmer's Reference.

</DIV>

<H3>EXPORTS</H3>

<P><A NAME="change_key/2"><STRONG><CODE>change_key(RegHandle, Key) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>
<STRONG><CODE>Key = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Changes the current key to another key. Works like cd.
         The key can be specified as a relative path or as an
         absolute path, starting with \.

</DIV>

<P><A NAME="change_key_create/2"><STRONG><CODE>change_key_create(RegHandle, Key) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>
<STRONG><CODE>Key = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Creates a key, or just changes to it, if it is already there. Works
         like a combination of <CODE>mkdir</CODE> and <CODE>cd</CODE>. Calls the Win32 API function
         <CODE>RegCreateKeyEx()</CODE>.
        
<P>The registry must have been opened in write-mode.

</DIV>

<P><A NAME="close/1"><STRONG><CODE>close(RegHandle)-&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Closes the registry. After that, the <CODE>RegHandle</CODE> cannot
         be used.

</DIV>

<P><A NAME="current_key/1"><STRONG><CODE>current_key(RegHandle) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>
<STRONG><CODE>ReturnValue = {ok, string()}</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the path to the current key. This is the equivalent of <CODE>pwd</CODE>.
        
<P>Note that the current key is stored in the driver, and might be
         invalid (e.g. if the key has been removed).

</DIV>

<P><A NAME="delete_key/1"><STRONG><CODE>delete_key(RegHandle) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>
<STRONG><CODE>ReturnValue = ok | {error, ErrorId}</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes the current key, if it is valid. Calls the Win32 API
         function <CODE>RegDeleteKey()</CODE>. Note that this call does not change the current key,
         (unlike <CODE>change_key_create/2</CODE>.) This means that after the call, the
         current key is invalid.

</DIV>

<P><A NAME="delete_value/2"><STRONG><CODE>delete_value(RegHandle, Name) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>RegHandle = term()</CODE></STRONG><BR>
<STRONG><CODE>ReturnValue = ok | {error, ErrorId}</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes a named value on the current key. The atom <CODE>default</CODE> is
         used for the the default value.
        
<P>The registry must have been opened in write-mode.

</DIV>

<P><A NAME="expand/1"><STRONG><CODE>expand(String) -&#62; ExpandedString</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>String = string()</CODE></STRONG><BR>
<STRONG><CODE>ExpandedString = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Expands a string containing environment variables between percent
         characters. Anything between two % is taken for a environment
         variable, and is replaced by the value. Two consecutive % is replaced
         by one %.
        
<P>A variable name that is not in the environment, will result in an error.      

</DIV>

<P><A NAME="format_error/1"><STRONG><CODE>format_error(ErrorId) -&#62; ErrorString</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>ErrorId = atom()</CODE></STRONG><BR>
<STRONG><CODE>ErrorString = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Convert an POSIX errorcode to a string (by calling <CODE>erl_posix_msg:message</CODE>).

</DIV>

<P><A NAME="open/1"><STRONG><CODE>open(OpenModeList)-&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>OpenModeList = [OpenMode]</CODE></STRONG><BR>
<STRONG><CODE>OpenMode = read | write</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Opens the registry for reading or writing. The current key will be the root
         (<CODE>HKEY_CLASSES_ROOT</CODE>). The <CODE>read</CODE> flag in the mode list can be omitted.
        
<P>Use <CODE>change_key/2</CODE> with an absolute path after <CODE>open</CODE>.

</DIV>

<P><A NAME="set_value/3"><STRONG><CODE>set_value(RegHandle, Name, Value) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = string() | default</CODE></STRONG><BR>
<STRONG><CODE>Value = string() | integer() | binary()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Sets the named (or default) value to value. Calls the Win32
         API function <CODE>RegSetValueEx()</CODE>. The value can be of three types, and
         the corresponding registry type will be used. Currently the types supported
         are: <CODE>REG_DWORD</CODE> for integers, <CODE>REG_SZ</CODE> for strings and
         <CODE>REG_BINARY</CODE> for binaries. Other types cannot currently be added
         or changed.
        
<P>The registry must have been opened in write-mode.

</DIV>

<P><A NAME="sub_keys/1"><STRONG><CODE>sub_keys(RegHandle) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>ReturnValue = {ok, SubKeys} | {error, ErrorId}</CODE></STRONG><BR>
<STRONG><CODE>SubKeys = [SubKey]</CODE></STRONG><BR>
<STRONG><CODE>SubKey = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a list of subkeys to the current key. Calls the Win32
         API function <CODE>EnumRegKeysEx()</CODE>.
        
<P>Avoid calling this on the root keys, it can be slow.

</DIV>

<P><A NAME="value/2"><STRONG><CODE>value(RegHandle, Name) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Name = string() | default</CODE></STRONG><BR>
<STRONG><CODE>ReturnValue = {ok, Value}</CODE></STRONG><BR>
<STRONG><CODE>Value = string() | integer() | binary()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Retrieves the named value (or default) on the current key.
         Registry values of type <CODE>REG_SZ</CODE>, are returned as strings. Type <CODE>REG_DWORD</CODE>
         values are returned as integers. All other types are returned as binaries.

</DIV>

<P><A NAME="values/1"><STRONG><CODE>values(RegHandle) -&#62; ReturnValue</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>ReturnValue = {ok, ValuePairs}</CODE></STRONG><BR>
<STRONG><CODE>ValuePairs = [ValuePair]</CODE></STRONG><BR>
<STRONG><CODE>ValuePair = {Name, Value}</CODE></STRONG><BR>
<STRONG><CODE>Name = string | default</CODE></STRONG><BR>
<STRONG><CODE>Value = string() | integer() | binary()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Retrieves a list of all values on the current key. The values
         have types corresponding to the registry types, see <CODE>value</CODE>.
         Calls the Win32 API function <CODE>EnumRegValuesEx()</CODE>.

</DIV>

<H3>SEE ALSO</H3>
<DIV CLASS=REFBODY>

<P>Win32 Programmer's Reference (from Microsoft)

<P><CODE>erl_posix_msg</CODE>

<P>The Windows 95 Registry (book from O'Reilly)

</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Bjorn Gustavsson - support@erlang.ericsson.se<BR>
Jakob Cederlund - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>