1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>win32reg</title>
27
<prepared>Bjorn Gustavsson</prepared>
28
<responsible>NN</responsible>
30
<approved>nobody</approved>
32
<date>2000-08-10</date>
34
<file>win32reg.sgml</file>
36
<module>win32reg</module>
37
<modulesummary>win32reg provides access to the registry on Windows</modulesummary>
39
<p><c>win32reg</c> provides read and write access to the
40
registry on Windows. It is essentially a port driver wrapped around the
41
Win32 API calls for accessing the registry.</p>
42
<p>The registry is a hierarchical database, used to store various system
43
and software information in Windows. It is available in Windows 95 and
44
Windows NT. It contains installation data, and is updated by installers
45
and system programs. The Erlang installer updates the registry by adding
46
data that Erlang needs.</p>
47
<p>The registry contains keys and values. Keys are like the directories
48
in a file system, they form a hierarchy. Values are like files, they have
49
a name and a value, and also a type.</p>
50
<p>Paths to keys are left to right, with sub-keys to the right and backslash
51
between keys. (Remember that backslashes must be doubled in Erlang strings.)
52
Case is preserved but not significant.
53
Example: <c>"\\\\hkey_local_machine\\\\software\\\\Ericsson\\\\Erlang\\\\5.0"</c> is the key
54
for the installation data for the latest Erlang release.</p>
55
<p>There are six entry points in the Windows registry, top level keys. They can be
56
abbreviated in the <c>win32reg</c> module as:</p>
60
hkcr HKEY_CLASSES_ROOT
61
current_user HKEY_CURRENT_USER
62
hkcu HKEY_CURRENT_USER
63
local_machine HKEY_LOCAL_MACHINE
64
hklm HKEY_LOCAL_MACHINE
67
current_config HKEY_CURRENT_CONFIG
68
hkcc HKEY_CURRENT_CONFIG
69
dyn_data HKEY_DYN_DATA
70
hkdd HKEY_DYN_DATA</pre>
71
<p>The key above could be written as <c>"\\\\hklm\\\\software\\\\ericsson\\\\erlang\\\\5.0"</c>.</p>
72
<p>The <c>win32reg</c> module uses a current key. It works much like the
73
current directory. From the current key, values can be fetched, sub-keys
74
can be listed, and so on.</p>
75
<p>Under a key, any number of named values can be stored. They have name, and
77
<p>Currently, the <c>win32reg</c> module supports storing only the following
78
types: REG_DWORD, which is an
79
integer, REG_SZ which is a string and REG_BINARY which is a binary.
80
Other types can be read, and will be returned as binaries.</p>
81
<p>There is also a "default" value, which has the empty string as name. It is read and
82
written with the atom <c>default</c> instead of the name.</p>
83
<p>Some registry values are stored as strings with references to environment variables,
84
e.g. <c>"%SystemRoot%Windows"</c>. <c>SystemRoot</c> is an environment variable, and should be
85
replaced with its value. A function <c>expand/1</c> is provided, so that environment
86
variables surrounded in % can be expanded to their values.</p>
87
<p>For additional information on the Windows registry consult the Win32
88
Programmer's Reference.</p>
92
<name>change_key(RegHandle, Key) -> ReturnValue</name>
93
<fsummary>Move to a key in the registry</fsummary>
95
<v>RegHandle = term()</v>
99
<p>Changes the current key to another key. Works like cd.
100
The key can be specified as a relative path or as an
101
absolute path, starting with \\.</p>
105
<name>change_key_create(RegHandle, Key) -> ReturnValue</name>
106
<fsummary>Move to a key, create it if it is not there</fsummary>
108
<v>RegHandle = term()</v>
109
<v>Key = string()</v>
112
<p>Creates a key, or just changes to it, if it is already there. Works
113
like a combination of <c>mkdir</c> and <c>cd</c>. Calls the Win32 API function
114
<c>RegCreateKeyEx()</c>.</p>
115
<p>The registry must have been opened in write-mode.</p>
119
<name>close(RegHandle)-> ReturnValue</name>
120
<fsummary>Close the registry.</fsummary>
122
<v>RegHandle = term()</v>
125
<p>Closes the registry. After that, the <c>RegHandle</c> cannot
130
<name>current_key(RegHandle) -> ReturnValue</name>
131
<fsummary>Return the path to the current key.</fsummary>
133
<v>RegHandle = term()</v>
134
<v>ReturnValue = {ok, string()}</v>
137
<p>Returns the path to the current key. This is the equivalent of <c>pwd</c>.</p>
138
<p>Note that the current key is stored in the driver, and might be
139
invalid (e.g. if the key has been removed).</p>
143
<name>delete_key(RegHandle) -> ReturnValue</name>
144
<fsummary>Delete the current key</fsummary>
146
<v>RegHandle = term()</v>
147
<v>ReturnValue = ok | {error, ErrorId}</v>
150
<p>Deletes the current key, if it is valid. Calls the Win32 API
151
function <c>RegDeleteKey()</c>. Note that this call does not change the current key,
152
(unlike <c>change_key_create/2</c>.) This means that after the call, the
153
current key is invalid.</p>
157
<name>delete_value(RegHandle, Name) -> ReturnValue</name>
158
<fsummary>Delete the named value on the current key.</fsummary>
160
<v>RegHandle = term()</v>
161
<v>ReturnValue = ok | {error, ErrorId}</v>
164
<p>Deletes a named value on the current key. The atom <c>default</c> is
165
used for the the default value.</p>
166
<p>The registry must have been opened in write-mode.</p>
170
<name>expand(String) -> ExpandedString</name>
171
<fsummary>Expand a string with environment variables</fsummary>
173
<v>String = string()</v>
174
<v>ExpandedString = string()</v>
177
<p>Expands a string containing environment variables between percent
178
characters. Anything between two % is taken for a environment
179
variable, and is replaced by the value. Two consecutive % is replaced
181
<p>A variable name that is not in the environment, will result in an error.\011 </p>
185
<name>format_error(ErrorId) -> ErrorString</name>
186
<fsummary>Convert an POSIX errorcode to a string</fsummary>
188
<v>ErrorId = atom()</v>
189
<v>ErrorString = string()</v>
192
<p>Convert an POSIX errorcode to a string (by calling <c>erl_posix_msg:message</c>).</p>
196
<name>open(OpenModeList)-> ReturnValue</name>
197
<fsummary>Open the registry for reading or writing</fsummary>
199
<v>OpenModeList = [OpenMode]</v>
200
<v>OpenMode = read | write</v>
203
<p>Opens the registry for reading or writing. The current key will be the root
204
(<c>HKEY_CLASSES_ROOT</c>). The <c>read</c> flag in the mode list can be omitted.</p>
205
<p>Use <c>change_key/2</c> with an absolute path after <c>open</c>.</p>
209
<name>set_value(RegHandle, Name, Value) -> ReturnValue</name>
210
<fsummary>Set value at the current registry key with specified name.</fsummary>
212
<v>Name = string() | default</v>
213
<v>Value = string() | integer() | binary()</v>
216
<p>Sets the named (or default) value to value. Calls the Win32
217
API function <c>RegSetValueEx()</c>. The value can be of three types, and
218
the corresponding registry type will be used. Currently the types supported
219
are: <c>REG_DWORD</c> for integers, <c>REG_SZ</c> for strings and
220
<c>REG_BINARY</c> for binaries. Other types cannot currently be added
222
<p>The registry must have been opened in write-mode.</p>
226
<name>sub_keys(RegHandle) -> ReturnValue</name>
227
<fsummary>Get subkeys to the current key.</fsummary>
229
<v>ReturnValue = {ok, SubKeys} | {error, ErrorId}</v>
230
<v>SubKeys = [SubKey]</v>
231
<v>SubKey = string()</v>
234
<p>Returns a list of subkeys to the current key. Calls the Win32
235
API function <c>EnumRegKeysEx()</c>.</p>
236
<p>Avoid calling this on the root keys, it can be slow.</p>
240
<name>value(RegHandle, Name) -> ReturnValue</name>
241
<fsummary>Get the named value on the current key.</fsummary>
243
<v>Name = string() | default</v>
244
<v>ReturnValue = {ok, Value}</v>
245
<v>Value = string() | integer() | binary()</v>
248
<p>Retrieves the named value (or default) on the current key.
249
Registry values of type <c>REG_SZ</c>, are returned as strings. Type <c>REG_DWORD</c>
250
values are returned as integers. All other types are returned as binaries.</p>
254
<name>values(RegHandle) -> ReturnValue</name>
255
<fsummary>Get all values on the current key.</fsummary>
257
<v>ReturnValue = {ok, ValuePairs}</v>
258
<v>ValuePairs = [ValuePair]</v>
259
<v>ValuePair = {Name, Value}</v>
260
<v>Name = string | default</v>
261
<v>Value = string() | integer() | binary()</v>
264
<p>Retrieves a list of all values on the current key. The values
265
have types corresponding to the registry types, see <c>value</c>.
266
Calls the Win32 API function <c>EnumRegValuesEx()</c>.</p>
272
<title>SEE ALSO</title>
273
<p>Win32 Programmer's Reference (from Microsoft)</p>
274
<p><c>erl_posix_msg</c></p>
275
<p>The Windows 95 Registry (book from O'Reilly)</p>