blob: ecb723c09de48119901c24096a5dac76da1679c3 [file] [log] [blame]
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001/*
Fred Drake270e19b2000-06-29 16:14:14 +00002 _winreg.c
Guido van Rossum9f3712c2000-03-28 20:37:15 +00003
4 Windows Registry access module for Python.
5
6 * Simple registry access written by Mark Hammond in win32api
7 module circa 1995.
8 * Bill Tutt expanded the support significantly not long after.
9 * Numerous other people have submitted patches since then.
10 * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and
11 basic Unicode support added.
12
13*/
14
Guido van Rossum9f3712c2000-03-28 20:37:15 +000015#include "Python.h"
16#include "structmember.h"
17#include "malloc.h" /* for alloca */
Guido van Rossume7ba4952007-06-06 23:52:48 +000018#include "windows.h"
Guido van Rossum9f3712c2000-03-28 20:37:15 +000019
20static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK);
21static PyObject *PyHKEY_FromHKEY(HKEY h);
22static BOOL PyHKEY_Close(PyObject *obHandle);
23
24static char errNotAHandle[] = "Object is not a handle";
25
26/* The win32api module reports the function name that failed,
27 but this concept is not in the Python core.
28 Hopefully it will one day, and in the meantime I dont
29 want to lose this info...
30*/
31#define PyErr_SetFromWindowsErrWithFunction(rc, fnname) \
32 PyErr_SetFromWindowsErr(rc)
33
34/* Forward declares */
35
36/* Doc strings */
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000037PyDoc_STRVAR(module_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +000038"This module provides access to the Windows registry API.\n"
39"\n"
40"Functions:\n"
41"\n"
42"CloseKey() - Closes a registry key.\n"
43"ConnectRegistry() - Establishes a connection to a predefined registry handle\n"
44" on another computer.\n"
45"CreateKey() - Creates the specified key, or opens it if it already exists.\n"
46"DeleteKey() - Deletes the specified key.\n"
47"DeleteValue() - Removes a named value from the specified registry key.\n"
48"EnumKey() - Enumerates subkeys of the specified open registry key.\n"
49"EnumValue() - Enumerates values of the specified open registry key.\n"
50"FlushKey() - Writes all the attributes of the specified key to the registry.\n"
51"LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n"
52" registration information from a specified file into that subkey.\n"
53"OpenKey() - Alias for <om win32api.RegOpenKeyEx>\n"
54"OpenKeyEx() - Opens the specified key.\n"
55"QueryValue() - Retrieves the value associated with the unnamed value for a\n"
56" specified key in the registry.\n"
57"QueryValueEx() - Retrieves the type and data for a specified value name\n"
58" associated with an open registry key.\n"
59"QueryInfoKey() - Returns information about the specified key.\n"
60"SaveKey() - Saves the specified key, and all its subkeys a file.\n"
61"SetValue() - Associates a value with a specified key.\n"
62"SetValueEx() - Stores data in the value field of an open registry key.\n"
63"\n"
64"Special objects:\n"
65"\n"
66"HKEYType -- type object for HKEY objects\n"
67"error -- exception raised for Win32 errors\n"
68"\n"
69"Integer constants:\n"
70"Many constants are defined - see the documentation for each function\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000071"to see what constants are used, and where.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +000072
73
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000074PyDoc_STRVAR(CloseKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +000075"CloseKey(hkey) - Closes a previously opened registry key.\n"
76"\n"
77"The hkey argument specifies a previously opened key.\n"
78"\n"
79"Note that if the key is not closed using this method, it will be\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000080"closed when the hkey object is destroyed by Python.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +000081
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000082PyDoc_STRVAR(ConnectRegistry_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +000083"key = ConnectRegistry(computer_name, key) - "
84"Establishes a connection to a predefined registry handle on another computer.\n"
85"\n"
86"computer_name is the name of the remote computer, of the form \\\\computername.\n"
87" If None, the local computer is used.\n"
88"key is the predefined handle to connect to.\n"
89"\n"
90"The return value is the handle of the opened key.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000091"If the function fails, an EnvironmentError exception is raised.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +000092
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +000093PyDoc_STRVAR(CreateKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +000094"key = CreateKey(key, sub_key) - Creates or opens the specified key.\n"
95"\n"
96"key is an already open key, or one of the predefined HKEY_* constants\n"
97"sub_key is a string that names the key this method opens or creates.\n"
98" If key is one of the predefined keys, sub_key may be None. In that case,\n"
99" the handle returned is the same key handle passed in to the function.\n"
100"\n"
101"If the key already exists, this function opens the existing key\n"
102"\n"
103"The return value is the handle of the opened key.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000104"If the function fails, an exception is raised.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000105
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000106PyDoc_STRVAR(DeleteKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000107"DeleteKey(key, sub_key) - Deletes the specified key.\n"
108"\n"
109"key is an already open key, or any one of the predefined HKEY_* constants.\n"
110"sub_key is a string that must be a subkey of the key identified by the key parameter.\n"
111" This value must not be None, and the key may not have subkeys.\n"
112"\n"
113"This method can not delete keys with subkeys.\n"
114"\n"
115"If the method succeeds, the entire key, including all of its values,\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000116"is removed. If the method fails, an EnvironmentError exception is raised.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000117
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000118PyDoc_STRVAR(DeleteValue_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000119"DeleteValue(key, value) - Removes a named value from a registry key.\n"
120"\n"
121"key is an already open key, or any one of the predefined HKEY_* constants.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000122"value is a string that identifies the value to remove.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000123
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000124PyDoc_STRVAR(EnumKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000125"string = EnumKey(key, index) - Enumerates subkeys of an open registry key.\n"
126"\n"
127"key is an already open key, or any one of the predefined HKEY_* constants.\n"
128"index is an integer that identifies the index of the key to retrieve.\n"
129"\n"
130"The function retrieves the name of one subkey each time it is called.\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000131"It is typically called repeatedly until an EnvironmentError exception is\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000132"raised, indicating no more values are available.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000133
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000134PyDoc_STRVAR(EnumValue_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000135"tuple = EnumValue(key, index) - Enumerates values of an open registry key.\n"
136"key is an already open key, or any one of the predefined HKEY_* constants.\n"
137"index is an integer that identifies the index of the value to retrieve.\n"
138"\n"
139"The function retrieves the name of one subkey each time it is called.\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000140"It is typically called repeatedly, until an EnvironmentError exception\n"
141"is raised, indicating no more values.\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000142"\n"
143"The result is a tuple of 3 items:\n"
144"value_name is a string that identifies the value.\n"
145"value_data is an object that holds the value data, and whose type depends\n"
146" on the underlying registry type.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000147"data_type is an integer that identifies the type of the value data.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000148
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000149PyDoc_STRVAR(FlushKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000150"FlushKey(key) - Writes all the attributes of a key to the registry.\n"
151"\n"
152"key is an already open key, or any one of the predefined HKEY_* constants.\n"
153"\n"
154"It is not necessary to call RegFlushKey to change a key.\n"
155"Registry changes are flushed to disk by the registry using its lazy flusher.\n"
156"Registry changes are also flushed to disk at system shutdown.\n"
157"Unlike CloseKey(), the FlushKey() method returns only when all the data has\n"
158"been written to the registry.\n"
159"An application should only call FlushKey() if it requires absolute certainty that registry changes are on disk.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000160"If you don't know whether a FlushKey() call is required, it probably isn't.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000161
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000162PyDoc_STRVAR(LoadKey_doc,
Mark Hammondb422f952000-06-09 06:01:47 +0000163"LoadKey(key, sub_key, file_name) - Creates a subkey under the specified key\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000164"and stores registration information from a specified file into that subkey.\n"
165"\n"
166"key is an already open key, or any one of the predefined HKEY_* constants.\n"
167"sub_key is a string that identifies the sub_key to load\n"
168"file_name is the name of the file to load registry data from.\n"
169" This file must have been created with the SaveKey() function.\n"
170" Under the file allocation table (FAT) file system, the filename may not\n"
171"have an extension.\n"
172"\n"
173"A call to LoadKey() fails if the calling process does not have the\n"
174"SE_RESTORE_PRIVILEGE privilege.\n"
175"\n"
176"If key is a handle returned by ConnectRegistry(), then the path specified\n"
177"in fileName is relative to the remote computer.\n"
178"\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000179"The docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE tree");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000180
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000181PyDoc_STRVAR(OpenKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000182"key = OpenKey(key, sub_key, res = 0, sam = KEY_READ) - Opens the specified key.\n"
183"\n"
184"key is an already open key, or any one of the predefined HKEY_* constants.\n"
185"sub_key is a string that identifies the sub_key to open\n"
186"res is a reserved integer, and must be zero. Default is zero.\n"
187"sam is an integer that specifies an access mask that describes the desired\n"
188" security access for the key. Default is KEY_READ\n"
189"\n"
190"The result is a new handle to the specified key\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000191"If the function fails, an EnvironmentError exception is raised.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000192
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000193PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000194
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000195PyDoc_STRVAR(QueryInfoKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000196"tuple = QueryInfoKey(key) - Returns information about a key.\n"
197"\n"
198"key is an already open key, or any one of the predefined HKEY_* constants.\n"
199"\n"
200"The result is a tuple of 3 items:"
201"An integer that identifies the number of sub keys this key has.\n"
202"An integer that identifies the number of values this key has.\n"
203"A long integer that identifies when the key was last modified (if available)\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000204" as 100's of nanoseconds since Jan 1, 1600.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000205
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000206PyDoc_STRVAR(QueryValue_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000207"string = QueryValue(key, sub_key) - retrieves the unnamed value for a key.\n"
208"\n"
209"key is an already open key, or any one of the predefined HKEY_* constants.\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000210"sub_key is a string that holds the name of the subkey with which the value\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000211" is associated. If this parameter is None or empty, the function retrieves\n"
212" the value set by the SetValue() method for the key identified by key."
213"\n"
214"Values in the registry have name, type, and data components. This method\n"
215"retrieves the data for a key's first value that has a NULL name.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000216"But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE THIS!!!");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000217
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000218PyDoc_STRVAR(QueryValueEx_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000219"value,type_id = QueryValueEx(key, value_name) - Retrieves the type and data for a specified value name associated with an open registry key.\n"
220"\n"
221"key is an already open key, or any one of the predefined HKEY_* constants.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000222"value_name is a string indicating the value to query");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000223
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000224PyDoc_STRVAR(SaveKey_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000225"SaveKey(key, file_name) - Saves the specified key, and all its subkeys to the specified file.\n"
226"\n"
227"key is an already open key, or any one of the predefined HKEY_* constants.\n"
228"file_name is the name of the file to save registry data to.\n"
229" This file cannot already exist. If this filename includes an extension,\n"
230" it cannot be used on file allocation table (FAT) file systems by the\n"
231" LoadKey(), ReplaceKey() or RestoreKey() methods.\n"
232"\n"
233"If key represents a key on a remote computer, the path described by\n"
234"file_name is relative to the remote computer.\n"
235"The caller of this method must possess the SeBackupPrivilege security privilege.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000236"This function passes NULL for security_attributes to the API.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000237
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000238PyDoc_STRVAR(SetValue_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000239"SetValue(key, sub_key, type, value) - Associates a value with a specified key.\n"
240"\n"
241"key is an already open key, or any one of the predefined HKEY_* constants.\n"
242"sub_key is a string that names the subkey with which the value is associated.\n"
243"type is an integer that specifies the type of the data. Currently this\n"
244" must be REG_SZ, meaning only strings are supported.\n"
245"value is a string that specifies the new value.\n"
246"\n"
247"If the key specified by the sub_key parameter does not exist, the SetValue\n"
248"function creates it.\n"
249"\n"
250"Value lengths are limited by available memory. Long values (more than\n"
251"2048 bytes) should be stored as files with the filenames stored in \n"
252"the configuration registry. This helps the registry perform efficiently.\n"
253"\n"
254"The key identified by the key parameter must have been opened with\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000255"KEY_SET_VALUE access.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000256
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000257PyDoc_STRVAR(SetValueEx_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000258"SetValueEx(key, value_name, reserved, type, value) - Stores data in the value field of an open registry key.\n"
259"\n"
260"key is an already open key, or any one of the predefined HKEY_* constants.\n"
Mark Hammondc9083b62003-01-15 23:38:15 +0000261"value_name is a string containing the name of the value to set, or None\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000262"type is an integer that specifies the type of the data. This should be one of:\n"
263" REG_BINARY -- Binary data in any form.\n"
264" REG_DWORD -- A 32-bit number.\n"
265" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n"
266" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
267" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references\n"
268" to environment variables (for example, %PATH%).\n"
269" REG_LINK -- A Unicode symbolic link.\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000270" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n"
271" two null characters. Note that Python handles this\n"
272" termination automatically.\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000273" REG_NONE -- No defined value type.\n"
274" REG_RESOURCE_LIST -- A device-driver resource list.\n"
275" REG_SZ -- A null-terminated string.\n"
276"reserved can be anything - zero is always passed to the API.\n"
277"value is a string that specifies the new value.\n"
278"\n"
279"This method can also set additional value and type information for the\n"
280"specified key. The key identified by the key parameter must have been\n"
281"opened with KEY_SET_VALUE access.\n"
282"\n"
283"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
284"\n"
285"Value lengths are limited by available memory. Long values (more than\n"
286"2048 bytes) should be stored as files with the filenames stored in \n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000287"the configuration registry. This helps the registry perform efficiently.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000288
289/* PyHKEY docstrings */
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000290PyDoc_STRVAR(PyHKEY_doc,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000291"PyHKEY Object - A Python object, representing a win32 registry key.\n"
292"\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000293"This object wraps a Windows HKEY object, automatically closing it when\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000294"the object is destroyed. To guarantee cleanup, you can call either\n"
295"the Close() method on the PyHKEY, or the CloseKey() method.\n"
296"\n"
297"All functions which accept a handle object also accept an integer - \n"
298"however, use of the handle object is encouraged.\n"
299"\n"
300"Functions:\n"
301"Close() - Closes the underlying handle.\n"
302"Detach() - Returns the integer Win32 handle, detaching it from the object\n"
303"\n"
304"Properties:\n"
305"handle - The integer Win32 handle.\n"
306"\n"
307"Operations:\n"
Jack Diederich4dafcc42006-11-28 19:15:13 +0000308"__bool__ - Handles with an open object return true, otherwise false.\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000309"__int__ - Converting a handle to an integer returns the Win32 handle.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000310"__cmp__ - Handle objects are compared using the handle value.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000311
312
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000313PyDoc_STRVAR(PyHKEY_Close_doc,
Mark Hammondb422f952000-06-09 06:01:47 +0000314"key.Close() - Closes the underlying Windows handle.\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000315"\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000316"If the handle is already closed, no error is raised.");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000317
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000318PyDoc_STRVAR(PyHKEY_Detach_doc,
Mark Hammondb422f952000-06-09 06:01:47 +0000319"int = key.Detach() - Detaches the Windows handle from the handle object.\n"
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000320"\n"
321"The result is the value of the handle before it is detached. If the\n"
322"handle is already detached, this will return zero.\n"
323"\n"
324"After calling this function, the handle is effectively invalidated,\n"
325"but the handle is not closed. You would call this function when you\n"
326"need the underlying win32 handle to exist beyond the lifetime of the\n"
Mark Hammondb422f952000-06-09 06:01:47 +0000327"handle object.\n"
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000328"On 64 bit windows, the result of this function is a long integer");
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000329
330
331/************************************************************************
332
333 The PyHKEY object definition
334
335************************************************************************/
336typedef struct {
337 PyObject_VAR_HEAD
338 HKEY hkey;
339} PyHKEYObject;
340
341#define PyHKEY_Check(op) ((op)->ob_type == &PyHKEY_Type)
342
343static char *failMsg = "bad operand type";
344
345static PyObject *
346PyHKEY_unaryFailureFunc(PyObject *ob)
347{
348 PyErr_SetString(PyExc_TypeError, failMsg);
349 return NULL;
350}
351static PyObject *
352PyHKEY_binaryFailureFunc(PyObject *ob1, PyObject *ob2)
353{
354 PyErr_SetString(PyExc_TypeError, failMsg);
355 return NULL;
356}
357static PyObject *
358PyHKEY_ternaryFailureFunc(PyObject *ob1, PyObject *ob2, PyObject *ob3)
359{
360 PyErr_SetString(PyExc_TypeError, failMsg);
361 return NULL;
362}
363
364static void
365PyHKEY_deallocFunc(PyObject *ob)
366{
367 /* Can not call PyHKEY_Close, as the ob->tp_type
368 has already been cleared, thus causing the type
369 check to fail!
370 */
371 PyHKEYObject *obkey = (PyHKEYObject *)ob;
372 if (obkey->hkey)
373 RegCloseKey((HKEY)obkey->hkey);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000374 PyObject_DEL(ob);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000375}
376
377static int
Jack Diederich4dafcc42006-11-28 19:15:13 +0000378PyHKEY_boolFunc(PyObject *ob)
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000379{
380 return ((PyHKEYObject *)ob)->hkey != 0;
381}
382
383static PyObject *
384PyHKEY_intFunc(PyObject *ob)
385{
386 PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
387 return PyLong_FromVoidPtr(pyhkey->hkey);
388}
389
390static int
391PyHKEY_printFunc(PyObject *ob, FILE *fp, int flags)
392{
393 PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
394 char resBuf[160];
395 wsprintf(resBuf, "<PyHKEY at %p (%p)>",
396 ob, pyhkey->hkey);
397 fputs(resBuf, fp);
398 return 0;
399}
400
401static PyObject *
402PyHKEY_strFunc(PyObject *ob)
403{
404 PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
405 char resBuf[160];
406 wsprintf(resBuf, "<PyHKEY:%p>", pyhkey->hkey);
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000407 return PyUnicode_FromString(resBuf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000408}
409
410static int
411PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2)
412{
413 PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
414 PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
415 return pyhkey1 == pyhkey2 ? 0 :
416 (pyhkey1 < pyhkey2 ? -1 : 1);
417}
418
419static long
420PyHKEY_hashFunc(PyObject *ob)
421{
422 /* Just use the address.
423 XXX - should we use the handle value?
424 */
Fred Drake13634cf2000-06-29 19:17:04 +0000425 return _Py_HashPointer(ob);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000426}
427
428
429static PyNumberMethods PyHKEY_NumberMethods =
430{
431 PyHKEY_binaryFailureFunc, /* nb_add */
432 PyHKEY_binaryFailureFunc, /* nb_subtract */
433 PyHKEY_binaryFailureFunc, /* nb_multiply */
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000434 PyHKEY_binaryFailureFunc, /* nb_remainder */
435 PyHKEY_binaryFailureFunc, /* nb_divmod */
436 PyHKEY_ternaryFailureFunc, /* nb_power */
437 PyHKEY_unaryFailureFunc, /* nb_negative */
438 PyHKEY_unaryFailureFunc, /* nb_positive */
439 PyHKEY_unaryFailureFunc, /* nb_absolute */
Jack Diederich4dafcc42006-11-28 19:15:13 +0000440 PyHKEY_boolFunc, /* nb_bool */
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000441 PyHKEY_unaryFailureFunc, /* nb_invert */
442 PyHKEY_binaryFailureFunc, /* nb_lshift */
443 PyHKEY_binaryFailureFunc, /* nb_rshift */
444 PyHKEY_binaryFailureFunc, /* nb_and */
445 PyHKEY_binaryFailureFunc, /* nb_xor */
446 PyHKEY_binaryFailureFunc, /* nb_or */
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000447 NULL, /* nb_coerce */
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000448 PyHKEY_intFunc, /* nb_int */
449 PyHKEY_unaryFailureFunc, /* nb_long */
450 PyHKEY_unaryFailureFunc, /* nb_float */
451 PyHKEY_unaryFailureFunc, /* nb_oct */
452 PyHKEY_unaryFailureFunc, /* nb_hex */
453};
454
455
456/* fwd declare __getattr__ */
Tim Petersc3d12ac2005-12-24 06:03:06 +0000457static PyObject *PyHKEY_getattr(PyObject *self, const char *name);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000458
459/* The type itself */
460PyTypeObject PyHKEY_Type =
461{
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000462 PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000463 "PyHKEY",
464 sizeof(PyHKEYObject),
465 0,
466 PyHKEY_deallocFunc, /* tp_dealloc */
467 PyHKEY_printFunc, /* tp_print */
468 PyHKEY_getattr, /* tp_getattr */
469 0, /* tp_setattr */
470 PyHKEY_compareFunc, /* tp_compare */
471 0, /* tp_repr */
472 &PyHKEY_NumberMethods, /* tp_as_number */
473 0, /* tp_as_sequence */
474 0, /* tp_as_mapping */
475 PyHKEY_hashFunc, /* tp_hash */
476 0, /* tp_call */
477 PyHKEY_strFunc, /* tp_str */
478 0, /* tp_getattro */
479 0, /* tp_setattro */
480 0, /* tp_as_buffer */
481 0, /* tp_flags */
482 PyHKEY_doc, /* tp_doc */
483};
484
485#define OFF(e) offsetof(PyHKEYObject, e)
486
487static struct memberlist PyHKEY_memberlist[] = {
488 {"handle", T_INT, OFF(hkey)},
489 {NULL} /* Sentinel */
490};
491
492/************************************************************************
493
494 The PyHKEY object methods
495
496************************************************************************/
497static PyObject *
498PyHKEY_CloseMethod(PyObject *self, PyObject *args)
499{
500 if (!PyArg_ParseTuple(args, ":Close"))
501 return NULL;
502 if (!PyHKEY_Close(self))
503 return NULL;
504 Py_INCREF(Py_None);
505 return Py_None;
506}
507
508static PyObject *
509PyHKEY_DetachMethod(PyObject *self, PyObject *args)
510{
511 void* ret;
512 PyHKEYObject *pThis = (PyHKEYObject *)self;
513 if (!PyArg_ParseTuple(args, ":Detach"))
514 return NULL;
515 ret = (void*)pThis->hkey;
516 pThis->hkey = 0;
517 return PyLong_FromVoidPtr(ret);
518}
519
520static struct PyMethodDef PyHKEY_methods[] = {
Neal Norwitz031829d2002-03-31 14:37:44 +0000521 {"Close", PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc},
522 {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc},
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000523 {NULL}
524};
525
526/*static*/ PyObject *
Tim Petersc3d12ac2005-12-24 06:03:06 +0000527PyHKEY_getattr(PyObject *self, const char *name)
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000528{
529 PyObject *res;
530
531 res = Py_FindMethod(PyHKEY_methods, self, name);
532 if (res != NULL)
533 return res;
534 PyErr_Clear();
535 if (strcmp(name, "handle") == 0)
536 return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey);
537 return PyMember_Get((char *)self, PyHKEY_memberlist, name);
538}
539
540/************************************************************************
541 The public PyHKEY API (well, not public yet :-)
542************************************************************************/
543PyObject *
544PyHKEY_New(HKEY hInit)
545{
546 PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type);
547 if (key)
548 key->hkey = hInit;
549 return (PyObject *)key;
550}
551
552BOOL
553PyHKEY_Close(PyObject *ob_handle)
554{
555 LONG rc;
556 PyHKEYObject *key;
557
558 if (!PyHKEY_Check(ob_handle)) {
559 PyErr_SetString(PyExc_TypeError, "bad operand type");
560 return FALSE;
561 }
562 key = (PyHKEYObject *)ob_handle;
563 rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS;
564 key->hkey = 0;
565 if (rc != ERROR_SUCCESS)
566 PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
567 return rc == ERROR_SUCCESS;
568}
569
570BOOL
571PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
572{
573 if (ob == Py_None) {
574 if (!bNoneOK) {
575 PyErr_SetString(
576 PyExc_TypeError,
577 "None is not a valid HKEY in this context");
578 return FALSE;
579 }
580 *pHANDLE = (HKEY)0;
581 }
582 else if (PyHKEY_Check(ob)) {
583 PyHKEYObject *pH = (PyHKEYObject *)ob;
584 *pHANDLE = pH->hkey;
585 }
586 else if (PyInt_Check(ob) || PyLong_Check(ob)) {
587 /* We also support integers */
588 PyErr_Clear();
589 *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
590 if (PyErr_Occurred())
591 return FALSE;
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000592 }
593 else {
594 PyErr_SetString(
595 PyExc_TypeError,
596 "The object is not a PyHKEY object");
597 return FALSE;
598 }
599 return TRUE;
600}
601
602PyObject *
603PyHKEY_FromHKEY(HKEY h)
604{
Guido van Rossumb18618d2000-05-03 23:44:39 +0000605 PyHKEYObject *op;
606
Guido van Rossume3a8e7e2002-08-19 19:26:42 +0000607 /* Inline PyObject_New */
Guido van Rossumb18618d2000-05-03 23:44:39 +0000608 op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000609 if (op == NULL)
610 return PyErr_NoMemory();
Guido van Rossumb18618d2000-05-03 23:44:39 +0000611 PyObject_INIT(op, &PyHKEY_Type);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000612 op->hkey = h;
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000613 return (PyObject *)op;
614}
615
616
617/************************************************************************
618 The module methods
619************************************************************************/
620BOOL
621PyWinObject_CloseHKEY(PyObject *obHandle)
622{
623 BOOL ok;
624 if (PyHKEY_Check(obHandle)) {
625 ok = PyHKEY_Close(obHandle);
626 }
Fred Drake25e17262000-06-30 17:48:51 +0000627#if SIZEOF_LONG >= SIZEOF_HKEY
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000628 else if (PyInt_Check(obHandle)) {
629 long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
630 ok = (rc == ERROR_SUCCESS);
631 if (!ok)
632 PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
633 }
Fred Drake25e17262000-06-30 17:48:51 +0000634#else
635 else if (PyLong_Check(obHandle)) {
636 long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
637 ok = (rc == ERROR_SUCCESS);
638 if (!ok)
639 PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
640 }
641#endif
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000642 else {
643 PyErr_SetString(
644 PyExc_TypeError,
645 "A handle must be a HKEY object or an integer");
646 return FALSE;
647 }
648 return ok;
649}
650
651
652/*
653 Private Helper functions for the registry interfaces
654
655** Note that fixupMultiSZ and countString have both had changes
656** made to support "incorrect strings". The registry specification
657** calls for strings to be terminated with 2 null bytes. It seems
Thomas Wouters7e474022000-07-16 12:04:32 +0000658** some commercial packages install strings which dont conform,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000659** causing this code to fail - however, "regedit" etc still work
660** with these strings (ie only we dont!).
661*/
662static void
663fixupMultiSZ(char **str, char *data, int len)
664{
665 char *P;
666 int i;
667 char *Q;
668
669 Q = data + len;
670 for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
671 str[i] = P;
672 for(; *P != '\0'; P++)
673 ;
674 }
675}
676
677static int
678countStrings(char *data, int len)
679{
680 int strings;
681 char *P;
682 char *Q = data + len;
683
684 for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++)
685 for (; P < Q && *P != '\0'; P++)
686 ;
687 return strings;
688}
689
690/* Convert PyObject into Registry data.
691 Allocates space as needed. */
692static BOOL
693Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
694{
695 int i,j;
Guido van Rossum7eaf8222007-06-18 17:58:50 +0000696 DWORD d;
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000697 switch (typ) {
698 case REG_DWORD:
Guido van Rossum7eaf8222007-06-18 17:58:50 +0000699 if (value != Py_None && !PyLong_Check(value))
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000700 return FALSE;
Guido van Rossumd8faa362007-04-27 19:54:29 +0000701 *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000702 if (*retDataBuf==NULL){
703 PyErr_NoMemory();
704 return FALSE;
705 }
706 *retDataSize = sizeof(DWORD);
707 if (value == Py_None) {
708 DWORD zero = 0;
709 memcpy(*retDataBuf, &zero, sizeof(DWORD));
710 }
Guido van Rossum7eaf8222007-06-18 17:58:50 +0000711 else {
712 d = PyLong_AsLong(value);
713 memcpy(*retDataBuf, &d, sizeof(DWORD));
714 }
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000715 break;
716 case REG_SZ:
717 case REG_EXPAND_SZ:
718 {
719 int need_decref = 0;
720 if (value == Py_None)
721 *retDataSize = 1;
722 else {
723 if (PyUnicode_Check(value)) {
724 value = PyUnicode_AsEncodedString(
725 value,
726 "mbcs",
727 NULL);
728 if (value==NULL)
729 return FALSE;
730 need_decref = 1;
731 }
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000732 if (!PyBytes_Check(value))
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000733 return FALSE;
734 *retDataSize = 1 + strlen(
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000735 PyBytes_AS_STRING(value));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000736 }
737 *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize);
738 if (*retDataBuf==NULL){
739 PyErr_NoMemory();
740 return FALSE;
741 }
742 if (value == Py_None)
743 strcpy((char *)*retDataBuf, "");
744 else
745 strcpy((char *)*retDataBuf,
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000746 PyBytes_AS_STRING(value));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000747 if (need_decref)
748 Py_DECREF(value);
749 break;
750 }
751 case REG_MULTI_SZ:
752 {
753 DWORD size = 0;
754 char *P;
755 PyObject **obs = NULL;
756
757 if (value == Py_None)
758 i = 0;
759 else {
760 if (!PyList_Check(value))
761 return FALSE;
762 i = PyList_Size(value);
763 }
764 obs = malloc(sizeof(PyObject *) * i);
765 memset(obs, 0, sizeof(PyObject *) * i);
766 for (j = 0; j < i; j++)
767 {
768 PyObject *t;
769 t = PyList_GET_ITEM(
770 (PyListObject *)value,j);
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000771 if (PyBytes_Check(t)) {
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000772 obs[j] = t;
773 Py_INCREF(t);
774 } else if (PyUnicode_Check(t)) {
775 obs[j] = PyUnicode_AsEncodedString(
776 t,
777 "mbcs",
778 NULL);
779 if (obs[j]==NULL)
780 goto reg_multi_fail;
781 } else
782 goto reg_multi_fail;
783 size += 1 + strlen(
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000784 PyBytes_AS_STRING(obs[j]));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000785 }
786
787 *retDataSize = size + 1;
788 *retDataBuf = (BYTE *)PyMem_NEW(char,
789 *retDataSize);
790 if (*retDataBuf==NULL){
791 PyErr_NoMemory();
792 goto reg_multi_fail;
793 }
794 P = (char *)*retDataBuf;
795
796 for (j = 0; j < i; j++)
797 {
798 PyObject *t;
799 t = obs[j];
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000800 strcpy(P, PyBytes_AS_STRING(t));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000801 P += 1 + strlen(
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000802 PyBytes_AS_STRING(t));
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000803 Py_DECREF(obs[j]);
804 }
805 /* And doubly-terminate the list... */
806 *P = '\0';
807 free(obs);
808 break;
809 reg_multi_fail:
810 if (obs) {
811 for (j = 0; j < i; j++)
812 Py_XDECREF(obs[j]);
813
814 free(obs);
815 }
816 return FALSE;
817 }
818 case REG_BINARY:
819 /* ALSO handle ALL unknown data types here. Even if we can't
820 support it natively, we should handle the bits. */
821 default:
822 if (value == Py_None)
823 *retDataSize = 0;
824 else {
Mark Hammond4e80bb52000-07-28 03:44:41 +0000825 void *src_buf;
826 PyBufferProcs *pb = value->ob_type->tp_as_buffer;
827 if (pb==NULL) {
Tim Peters313fcd42006-02-19 04:05:39 +0000828 PyErr_Format(PyExc_TypeError,
Mark Hammond4e80bb52000-07-28 03:44:41 +0000829 "Objects of type '%s' can not "
Tim Peters313fcd42006-02-19 04:05:39 +0000830 "be used as binary registry values",
Mark Hammond4e80bb52000-07-28 03:44:41 +0000831 value->ob_type->tp_name);
832 return FALSE;
833 }
834 *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000835 *retDataBuf = (BYTE *)PyMem_NEW(char,
836 *retDataSize);
837 if (*retDataBuf==NULL){
838 PyErr_NoMemory();
839 return FALSE;
840 }
Mark Hammond4e80bb52000-07-28 03:44:41 +0000841 memcpy(*retDataBuf, src_buf, *retDataSize);
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000842 }
843 break;
844 }
845 return TRUE;
846}
847
848/* Convert Registry data into PyObject*/
849static PyObject *
850Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
851{
852 PyObject *obData;
853
854 switch (typ) {
855 case REG_DWORD:
856 if (retDataSize == 0)
857 obData = Py_BuildValue("i", 0);
858 else
859 obData = Py_BuildValue("i",
860 *(int *)retDataBuf);
861 break;
862 case REG_SZ:
863 case REG_EXPAND_SZ:
864 /* retDataBuf may or may not have a trailing NULL in
865 the buffer. */
866 if (retDataSize && retDataBuf[retDataSize-1] == '\0')
867 --retDataSize;
868 if (retDataSize ==0)
869 retDataBuf = "";
870 obData = PyUnicode_DecodeMBCS(retDataBuf,
871 retDataSize,
872 NULL);
873 break;
874 case REG_MULTI_SZ:
875 if (retDataSize == 0)
876 obData = PyList_New(0);
877 else
878 {
879 int index = 0;
880 int s = countStrings(retDataBuf, retDataSize);
881 char **str = (char **)malloc(sizeof(char *)*s);
882 if (str == NULL)
883 return PyErr_NoMemory();
884
885 fixupMultiSZ(str, retDataBuf, retDataSize);
886 obData = PyList_New(s);
Fred Drake25e17262000-06-30 17:48:51 +0000887 if (obData == NULL)
888 return NULL;
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000889 for (index = 0; index < s; index++)
890 {
Fred Drake25e17262000-06-30 17:48:51 +0000891 size_t len = _mbstrlen(str[index]);
892 if (len > INT_MAX) {
893 PyErr_SetString(PyExc_OverflowError,
894 "registry string is too long for a Python string");
895 Py_DECREF(obData);
896 return NULL;
897 }
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000898 PyList_SetItem(obData,
899 index,
900 PyUnicode_DecodeMBCS(
901 (const char *)str[index],
Fred Drake25e17262000-06-30 17:48:51 +0000902 (int)len,
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000903 NULL)
904 );
905 }
906 free(str);
907
908 break;
909 }
910 case REG_BINARY:
911 /* ALSO handle ALL unknown data types here. Even if we can't
912 support it natively, we should handle the bits. */
913 default:
914 if (retDataSize == 0) {
915 Py_INCREF(Py_None);
916 obData = Py_None;
917 }
918 else
Guido van Rossuma8c360e2007-07-17 20:50:43 +0000919 obData = Py_BuildValue("y#",
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000920 (char *)retDataBuf,
921 retDataSize);
922 break;
923 }
924 if (obData == NULL)
925 return NULL;
926 else
927 return obData;
928}
929
930/* The Python methods */
931
932static PyObject *
933PyCloseKey(PyObject *self, PyObject *args)
934{
935 PyObject *obKey;
936 if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey))
937 return NULL;
938 if (!PyHKEY_Close(obKey))
939 return NULL;
940 Py_INCREF(Py_None);
941 return Py_None;
942}
943
944static PyObject *
945PyConnectRegistry(PyObject *self, PyObject *args)
946{
947 HKEY hKey;
948 PyObject *obKey;
949 char *szCompName = NULL;
950 HKEY retKey;
951 long rc;
952 if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey))
953 return NULL;
954 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
955 return NULL;
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000956 Py_BEGIN_ALLOW_THREADS
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000957 rc = RegConnectRegistry(szCompName, hKey, &retKey);
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000958 Py_END_ALLOW_THREADS
Guido van Rossum9f3712c2000-03-28 20:37:15 +0000959 if (rc != ERROR_SUCCESS)
960 return PyErr_SetFromWindowsErrWithFunction(rc,
961 "ConnectRegistry");
962 return PyHKEY_FromHKEY(retKey);
963}
964
965static PyObject *
966PyCreateKey(PyObject *self, PyObject *args)
967{
968 HKEY hKey;
969 PyObject *obKey;
970 char *subKey;
971 HKEY retKey;
972 long rc;
973 if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey))
974 return NULL;
975 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
976 return NULL;
977 rc = RegCreateKey(hKey, subKey, &retKey);
978 if (rc != ERROR_SUCCESS)
979 return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
980 return PyHKEY_FromHKEY(retKey);
981}
982
983static PyObject *
984PyDeleteKey(PyObject *self, PyObject *args)
985{
986 HKEY hKey;
987 PyObject *obKey;
988 char *subKey;
989 long rc;
990 if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey))
991 return NULL;
992 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
993 return NULL;
994 rc = RegDeleteKey(hKey, subKey );
995 if (rc != ERROR_SUCCESS)
996 return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
997 Py_INCREF(Py_None);
998 return Py_None;
999}
1000
1001static PyObject *
1002PyDeleteValue(PyObject *self, PyObject *args)
1003{
1004 HKEY hKey;
1005 PyObject *obKey;
1006 char *subKey;
1007 long rc;
1008 if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey))
1009 return NULL;
1010 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1011 return NULL;
1012 Py_BEGIN_ALLOW_THREADS
1013 rc = RegDeleteValue(hKey, subKey);
1014 Py_END_ALLOW_THREADS
1015 if (rc !=ERROR_SUCCESS)
1016 return PyErr_SetFromWindowsErrWithFunction(rc,
1017 "RegDeleteValue");
1018 Py_INCREF(Py_None);
1019 return Py_None;
1020}
1021
1022static PyObject *
1023PyEnumKey(PyObject *self, PyObject *args)
1024{
1025 HKEY hKey;
1026 PyObject *obKey;
1027 int index;
1028 long rc;
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001029 PyObject *retStr;
Georg Brandl9a928e72006-02-18 23:35:11 +00001030 char tmpbuf[256]; /* max key name length is 255 */
Georg Brandlb2699b22006-02-18 23:44:24 +00001031 DWORD len = sizeof(tmpbuf); /* includes NULL terminator */
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001032
1033 if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
1034 return NULL;
1035 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1036 return NULL;
Tim Peters313fcd42006-02-19 04:05:39 +00001037
Georg Brandl9a928e72006-02-18 23:35:11 +00001038 Py_BEGIN_ALLOW_THREADS
1039 rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
1040 Py_END_ALLOW_THREADS
1041 if (rc != ERROR_SUCCESS)
1042 return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
Tim Peters313fcd42006-02-19 04:05:39 +00001043
Guido van Rossuma8c360e2007-07-17 20:50:43 +00001044 retStr = PyUnicode_FromStringAndSize(tmpbuf, len);
Georg Brandl9a928e72006-02-18 23:35:11 +00001045 return retStr; /* can be NULL */
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001046}
1047
1048static PyObject *
1049PyEnumValue(PyObject *self, PyObject *args)
1050{
1051 HKEY hKey;
1052 PyObject *obKey;
1053 int index;
1054 long rc;
1055 char *retValueBuf;
1056 char *retDataBuf;
1057 DWORD retValueSize;
1058 DWORD retDataSize;
1059 DWORD typ;
1060 PyObject *obData;
1061 PyObject *retVal;
1062
1063 if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index))
1064 return NULL;
1065 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1066 return NULL;
1067
1068 if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
1069 NULL,
1070 &retValueSize, &retDataSize, NULL, NULL))
1071 != ERROR_SUCCESS)
1072 return PyErr_SetFromWindowsErrWithFunction(rc,
1073 "RegQueryInfoKey");
1074 ++retValueSize; /* include null terminators */
1075 ++retDataSize;
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001076 retValueBuf = (char *)PyMem_Malloc(retValueSize);
1077 if (retValueBuf == NULL)
1078 return PyErr_NoMemory();
1079 retDataBuf = (char *)PyMem_Malloc(retDataSize);
1080 if (retDataBuf == NULL) {
1081 PyMem_Free(retValueBuf);
1082 return PyErr_NoMemory();
1083 }
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001084
1085 Py_BEGIN_ALLOW_THREADS
1086 rc = RegEnumValue(hKey,
1087 index,
1088 retValueBuf,
1089 &retValueSize,
1090 NULL,
1091 &typ,
1092 (BYTE *)retDataBuf,
1093 &retDataSize);
1094 Py_END_ALLOW_THREADS
1095
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001096 if (rc != ERROR_SUCCESS) {
1097 retVal = PyErr_SetFromWindowsErrWithFunction(rc,
1098 "PyRegEnumValue");
1099 goto fail;
1100 }
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001101 obData = Reg2Py(retDataBuf, retDataSize, typ);
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001102 if (obData == NULL) {
1103 retVal = NULL;
1104 goto fail;
1105 }
Guido van Rossuma8c360e2007-07-17 20:50:43 +00001106 retVal = Py_BuildValue("UOi", retValueBuf, obData, typ);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001107 Py_DECREF(obData);
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001108 fail:
1109 PyMem_Free(retValueBuf);
1110 PyMem_Free(retDataBuf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001111 return retVal;
1112}
1113
1114static PyObject *
1115PyFlushKey(PyObject *self, PyObject *args)
1116{
1117 HKEY hKey;
1118 PyObject *obKey;
1119 long rc;
1120 if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey))
1121 return NULL;
1122 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1123 return NULL;
1124 Py_BEGIN_ALLOW_THREADS
1125 rc = RegFlushKey(hKey);
1126 Py_END_ALLOW_THREADS
1127 if (rc != ERROR_SUCCESS)
1128 return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey");
1129 Py_INCREF(Py_None);
1130 return Py_None;
1131}
1132static PyObject *
1133PyLoadKey(PyObject *self, PyObject *args)
1134{
1135 HKEY hKey;
1136 PyObject *obKey;
1137 char *subKey;
1138 char *fileName;
1139
1140 long rc;
1141 if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName))
1142 return NULL;
1143 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1144 return NULL;
1145 Py_BEGIN_ALLOW_THREADS
1146 rc = RegLoadKey(hKey, subKey, fileName );
1147 Py_END_ALLOW_THREADS
1148 if (rc != ERROR_SUCCESS)
1149 return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey");
1150 Py_INCREF(Py_None);
1151 return Py_None;
1152}
1153
1154static PyObject *
1155PyOpenKey(PyObject *self, PyObject *args)
1156{
1157 HKEY hKey;
1158 PyObject *obKey;
1159
1160 char *subKey;
1161 int res = 0;
1162 HKEY retKey;
1163 long rc;
1164 REGSAM sam = KEY_READ;
1165 if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey,
1166 &res, &sam))
1167 return NULL;
1168 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1169 return NULL;
1170
1171 Py_BEGIN_ALLOW_THREADS
1172 rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey);
1173 Py_END_ALLOW_THREADS
1174 if (rc != ERROR_SUCCESS)
1175 return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
1176 return PyHKEY_FromHKEY(retKey);
1177}
1178
1179
1180static PyObject *
1181PyQueryInfoKey(PyObject *self, PyObject *args)
1182{
1183 HKEY hKey;
1184 PyObject *obKey;
1185 long rc;
1186 DWORD nSubKeys, nValues;
1187 FILETIME ft;
1188 LARGE_INTEGER li;
1189 PyObject *l;
1190 PyObject *ret;
1191 if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey))
1192 return NULL;
1193 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1194 return NULL;
1195 if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL,
1196 &nValues, NULL, NULL, NULL, &ft))
1197 != ERROR_SUCCESS)
1198 return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
1199 li.LowPart = ft.dwLowDateTime;
1200 li.HighPart = ft.dwHighDateTime;
1201 l = PyLong_FromLongLong(li.QuadPart);
1202 if (l == NULL)
1203 return NULL;
1204 ret = Py_BuildValue("iiO", nSubKeys, nValues, l);
1205 Py_DECREF(l);
1206 return ret;
1207}
1208
1209static PyObject *
1210PyQueryValue(PyObject *self, PyObject *args)
1211{
1212 HKEY hKey;
1213 PyObject *obKey;
1214 char *subKey;
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001215 long rc;
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001216 PyObject *retStr;
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001217 char *retBuf;
1218 long bufSize = 0;
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001219
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001220 if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey))
1221 return NULL;
1222
1223 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1224 return NULL;
1225 if ((rc = RegQueryValue(hKey, subKey, NULL, &bufSize))
1226 != ERROR_SUCCESS)
1227 return PyErr_SetFromWindowsErrWithFunction(rc,
1228 "RegQueryValue");
Guido van Rossuma8c360e2007-07-17 20:50:43 +00001229 retBuf = (char *)PyMem_Malloc(bufSize);
1230 if (retBuf == NULL)
1231 return PyErr_NoMemory();
1232
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001233 if ((rc = RegQueryValue(hKey, subKey, retBuf, &bufSize))
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001234 != ERROR_SUCCESS) {
Guido van Rossuma8c360e2007-07-17 20:50:43 +00001235 PyMem_Free(retBuf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001236 return PyErr_SetFromWindowsErrWithFunction(rc,
1237 "RegQueryValue");
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001238 }
Guido van Rossuma8c360e2007-07-17 20:50:43 +00001239
1240 retStr = PyUnicode_DecodeMBCS(retBuf, strlen(retBuf), NULL);
1241 PyMem_Free(retBuf);
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001242 return retStr;
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001243}
1244
1245static PyObject *
1246PyQueryValueEx(PyObject *self, PyObject *args)
1247{
1248 HKEY hKey;
1249 PyObject *obKey;
1250 char *valueName;
1251
1252 long rc;
1253 char *retBuf;
1254 DWORD bufSize = 0;
1255 DWORD typ;
1256 PyObject *obData;
1257 PyObject *result;
1258
1259 if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName))
1260 return NULL;
1261
1262 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1263 return NULL;
1264 if ((rc = RegQueryValueEx(hKey, valueName,
1265 NULL, NULL, NULL,
1266 &bufSize))
1267 != ERROR_SUCCESS)
1268 return PyErr_SetFromWindowsErrWithFunction(rc,
1269 "RegQueryValueEx");
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001270 retBuf = (char *)PyMem_Malloc(bufSize);
1271 if (retBuf == NULL)
1272 return PyErr_NoMemory();
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001273 if ((rc = RegQueryValueEx(hKey, valueName, NULL,
1274 &typ, (BYTE *)retBuf, &bufSize))
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001275 != ERROR_SUCCESS) {
1276 PyMem_Free(retBuf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001277 return PyErr_SetFromWindowsErrWithFunction(rc,
1278 "RegQueryValueEx");
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001279 }
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001280 obData = Reg2Py(retBuf, bufSize, typ);
Guido van Rossuma6a38ad2003-11-30 22:01:43 +00001281 PyMem_Free((void *)retBuf);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001282 if (obData == NULL)
1283 return NULL;
1284 result = Py_BuildValue("Oi", obData, typ);
1285 Py_DECREF(obData);
1286 return result;
1287}
1288
1289
1290static PyObject *
1291PySaveKey(PyObject *self, PyObject *args)
1292{
1293 HKEY hKey;
1294 PyObject *obKey;
1295 char *fileName;
1296 LPSECURITY_ATTRIBUTES pSA = NULL;
1297
1298 long rc;
1299 if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName))
1300 return NULL;
1301 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1302 return NULL;
1303/* One day we may get security into the core?
1304 if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE))
1305 return NULL;
1306*/
1307 Py_BEGIN_ALLOW_THREADS
1308 rc = RegSaveKey(hKey, fileName, pSA );
1309 Py_END_ALLOW_THREADS
1310 if (rc != ERROR_SUCCESS)
1311 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey");
1312 Py_INCREF(Py_None);
1313 return Py_None;
1314}
1315
1316static PyObject *
1317PySetValue(PyObject *self, PyObject *args)
1318{
1319 HKEY hKey;
1320 PyObject *obKey;
1321 char *subKey;
1322 char *str;
1323 DWORD typ;
1324 DWORD len;
1325 long rc;
1326 PyObject *obStrVal;
1327 PyObject *obSubKey;
1328 if (!PyArg_ParseTuple(args, "OOiO:SetValue",
1329 &obKey,
1330 &obSubKey,
1331 &typ,
1332 &obStrVal))
1333 return NULL;
1334 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1335 return NULL;
1336 if (typ != REG_SZ) {
1337 PyErr_SetString(PyExc_TypeError,
Thomas Hellere1d18f52002-12-20 20:13:35 +00001338 "Type must be _winreg.REG_SZ");
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001339 return NULL;
1340 }
1341 /* XXX - need Unicode support */
1342 str = PyString_AsString(obStrVal);
1343 if (str == NULL)
1344 return NULL;
1345 len = PyString_Size(obStrVal);
1346 if (obSubKey == Py_None)
1347 subKey = NULL;
1348 else {
1349 subKey = PyString_AsString(obSubKey);
1350 if (subKey == NULL)
1351 return NULL;
1352 }
1353 Py_BEGIN_ALLOW_THREADS
1354 rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1);
1355 Py_END_ALLOW_THREADS
1356 if (rc != ERROR_SUCCESS)
1357 return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue");
1358 Py_INCREF(Py_None);
1359 return Py_None;
1360}
1361
1362static PyObject *
1363PySetValueEx(PyObject *self, PyObject *args)
1364{
1365 HKEY hKey;
1366 PyObject *obKey;
1367 char *valueName;
1368 PyObject *obRes;
1369 PyObject *value;
1370 BYTE *data;
1371 DWORD len;
1372 DWORD typ;
1373
1374 LONG rc;
1375
1376 if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx",
1377 &obKey,
1378 &valueName,
1379 &obRes,
1380 &typ,
1381 &value))
1382 return NULL;
1383 if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
1384 return NULL;
1385 if (!Py2Reg(value, typ, &data, &len))
1386 {
1387 if (!PyErr_Occurred())
1388 PyErr_SetString(PyExc_ValueError,
1389 "Could not convert the data to the specified type.");
1390 return NULL;
1391 }
1392 Py_BEGIN_ALLOW_THREADS
1393 rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
1394 Py_END_ALLOW_THREADS
Guido van Rossumb18618d2000-05-03 23:44:39 +00001395 PyMem_DEL(data);
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001396 if (rc != ERROR_SUCCESS)
1397 return PyErr_SetFromWindowsErrWithFunction(rc,
1398 "RegSetValueEx");
1399 Py_INCREF(Py_None);
1400 return Py_None;
1401}
1402
1403static struct PyMethodDef winreg_methods[] = {
Neal Norwitz031829d2002-03-31 14:37:44 +00001404 {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc},
1405 {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc},
1406 {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc},
1407 {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc},
1408 {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc},
1409 {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc},
1410 {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc},
1411 {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc},
1412 {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc},
1413 {"OpenKey", PyOpenKey, METH_VARARGS, OpenKey_doc},
1414 {"OpenKeyEx", PyOpenKey, METH_VARARGS, OpenKeyEx_doc},
1415 {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc},
1416 {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc},
1417 {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc},
1418 {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc},
1419 {"SetValue", PySetValue, METH_VARARGS, SetValue_doc},
1420 {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc},
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001421 NULL,
1422};
1423
1424static void
1425insint(PyObject * d, char * name, long value)
1426{
1427 PyObject *v = PyInt_FromLong(value);
1428 if (!v || PyDict_SetItemString(d, name, v))
1429 PyErr_Clear();
1430 Py_XDECREF(v);
1431}
1432
1433#define ADD_INT(val) insint(d, #val, val)
1434
1435static void
1436inskey(PyObject * d, char * name, HKEY key)
1437{
1438 PyObject *v = PyLong_FromVoidPtr(key);
1439 if (!v || PyDict_SetItemString(d, name, v))
1440 PyErr_Clear();
1441 Py_XDECREF(v);
1442}
1443
1444#define ADD_KEY(val) inskey(d, #val, val)
1445
Mark Hammond8235ea12002-07-19 06:55:41 +00001446PyMODINIT_FUNC init_winreg(void)
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001447{
1448 PyObject *m, *d;
Fred Drake270e19b2000-06-29 16:14:14 +00001449 m = Py_InitModule3("_winreg", winreg_methods, module_doc);
Neal Norwitz1ac754f2006-01-19 06:09:39 +00001450 if (m == NULL)
1451 return;
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001452 d = PyModule_GetDict(m);
Martin v. Löwis95c95ce2007-07-22 14:41:55 +00001453 Py_Type(&PyHKEY_Type) = &PyType_Type;
Guido van Rossum9f3712c2000-03-28 20:37:15 +00001454 PyHKEY_Type.tp_doc = PyHKEY_doc;
1455 Py_INCREF(&PyHKEY_Type);
1456 if (PyDict_SetItemString(d, "HKEYType",
1457 (PyObject *)&PyHKEY_Type) != 0)
1458 return;
1459 Py_INCREF(PyExc_WindowsError);
1460 if (PyDict_SetItemString(d, "error",
1461 PyExc_WindowsError) != 0)
1462 return;
1463
1464 /* Add the relevant constants */
1465 ADD_KEY(HKEY_CLASSES_ROOT);
1466 ADD_KEY(HKEY_CURRENT_USER);
1467 ADD_KEY(HKEY_LOCAL_MACHINE);
1468 ADD_KEY(HKEY_USERS);
1469 ADD_KEY(HKEY_PERFORMANCE_DATA);
1470#ifdef HKEY_CURRENT_CONFIG
1471 ADD_KEY(HKEY_CURRENT_CONFIG);
1472#endif
1473#ifdef HKEY_DYN_DATA
1474 ADD_KEY(HKEY_DYN_DATA);
1475#endif
1476 ADD_INT(KEY_QUERY_VALUE);
1477 ADD_INT(KEY_SET_VALUE);
1478 ADD_INT(KEY_CREATE_SUB_KEY);
1479 ADD_INT(KEY_ENUMERATE_SUB_KEYS);
1480 ADD_INT(KEY_NOTIFY);
1481 ADD_INT(KEY_CREATE_LINK);
1482 ADD_INT(KEY_READ);
1483 ADD_INT(KEY_WRITE);
1484 ADD_INT(KEY_EXECUTE);
1485 ADD_INT(KEY_ALL_ACCESS);
1486 ADD_INT(REG_OPTION_RESERVED);
1487 ADD_INT(REG_OPTION_NON_VOLATILE);
1488 ADD_INT(REG_OPTION_VOLATILE);
1489 ADD_INT(REG_OPTION_CREATE_LINK);
1490 ADD_INT(REG_OPTION_BACKUP_RESTORE);
1491 ADD_INT(REG_OPTION_OPEN_LINK);
1492 ADD_INT(REG_LEGAL_OPTION);
1493 ADD_INT(REG_CREATED_NEW_KEY);
1494 ADD_INT(REG_OPENED_EXISTING_KEY);
1495 ADD_INT(REG_WHOLE_HIVE_VOLATILE);
1496 ADD_INT(REG_REFRESH_HIVE);
1497 ADD_INT(REG_NO_LAZY_FLUSH);
1498 ADD_INT(REG_NOTIFY_CHANGE_NAME);
1499 ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES);
1500 ADD_INT(REG_NOTIFY_CHANGE_LAST_SET);
1501 ADD_INT(REG_NOTIFY_CHANGE_SECURITY);
1502 ADD_INT(REG_LEGAL_CHANGE_FILTER);
1503 ADD_INT(REG_NONE);
1504 ADD_INT(REG_SZ);
1505 ADD_INT(REG_EXPAND_SZ);
1506 ADD_INT(REG_BINARY);
1507 ADD_INT(REG_DWORD);
1508 ADD_INT(REG_DWORD_LITTLE_ENDIAN);
1509 ADD_INT(REG_DWORD_BIG_ENDIAN);
1510 ADD_INT(REG_LINK);
1511 ADD_INT(REG_MULTI_SZ);
1512 ADD_INT(REG_RESOURCE_LIST);
1513 ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
1514 ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
1515}
1516