Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1 | /* |
Fred Drake | 270e19b | 2000-06-29 16:14:14 +0000 | [diff] [blame] | 2 | _winreg.c |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 3 | |
| 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 Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 15 | #include "Python.h" |
| 16 | #include "structmember.h" |
| 17 | #include "malloc.h" /* for alloca */ |
Kristján Valur Jónsson | 629ec26 | 2007-05-26 19:31:39 +0000 | [diff] [blame] | 18 | #include "windows.h" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 19 | |
| 20 | static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); |
| 21 | static PyObject *PyHKEY_FromHKEY(HKEY h); |
| 22 | static BOOL PyHKEY_Close(PyObject *obHandle); |
| 23 | |
| 24 | static 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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 37 | PyDoc_STRVAR(module_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 38 | "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" |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 50 | "ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ string.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 51 | "FlushKey() - Writes all the attributes of the specified key to the registry.\n" |
| 52 | "LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n" |
| 53 | " registration information from a specified file into that subkey.\n" |
| 54 | "OpenKey() - Alias for <om win32api.RegOpenKeyEx>\n" |
| 55 | "OpenKeyEx() - Opens the specified key.\n" |
| 56 | "QueryValue() - Retrieves the value associated with the unnamed value for a\n" |
| 57 | " specified key in the registry.\n" |
| 58 | "QueryValueEx() - Retrieves the type and data for a specified value name\n" |
| 59 | " associated with an open registry key.\n" |
| 60 | "QueryInfoKey() - Returns information about the specified key.\n" |
| 61 | "SaveKey() - Saves the specified key, and all its subkeys a file.\n" |
| 62 | "SetValue() - Associates a value with a specified key.\n" |
| 63 | "SetValueEx() - Stores data in the value field of an open registry key.\n" |
| 64 | "\n" |
| 65 | "Special objects:\n" |
| 66 | "\n" |
| 67 | "HKEYType -- type object for HKEY objects\n" |
| 68 | "error -- exception raised for Win32 errors\n" |
| 69 | "\n" |
| 70 | "Integer constants:\n" |
| 71 | "Many constants are defined - see the documentation for each function\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 72 | "to see what constants are used, and where."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 73 | |
| 74 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 75 | PyDoc_STRVAR(CloseKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 76 | "CloseKey(hkey) - Closes a previously opened registry key.\n" |
| 77 | "\n" |
| 78 | "The hkey argument specifies a previously opened key.\n" |
| 79 | "\n" |
| 80 | "Note that if the key is not closed using this method, it will be\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 81 | "closed when the hkey object is destroyed by Python."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 82 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 83 | PyDoc_STRVAR(ConnectRegistry_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 84 | "key = ConnectRegistry(computer_name, key) - " |
| 85 | "Establishes a connection to a predefined registry handle on another computer.\n" |
| 86 | "\n" |
| 87 | "computer_name is the name of the remote computer, of the form \\\\computername.\n" |
| 88 | " If None, the local computer is used.\n" |
| 89 | "key is the predefined handle to connect to.\n" |
| 90 | "\n" |
| 91 | "The return value is the handle of the opened key.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 92 | "If the function fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 93 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 94 | PyDoc_STRVAR(CreateKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 95 | "key = CreateKey(key, sub_key) - Creates or opens the specified key.\n" |
| 96 | "\n" |
| 97 | "key is an already open key, or one of the predefined HKEY_* constants\n" |
| 98 | "sub_key is a string that names the key this method opens or creates.\n" |
| 99 | " If key is one of the predefined keys, sub_key may be None. In that case,\n" |
| 100 | " the handle returned is the same key handle passed in to the function.\n" |
| 101 | "\n" |
| 102 | "If the key already exists, this function opens the existing key\n" |
| 103 | "\n" |
| 104 | "The return value is the handle of the opened key.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 105 | "If the function fails, an exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 106 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 107 | PyDoc_STRVAR(DeleteKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 108 | "DeleteKey(key, sub_key) - Deletes the specified key.\n" |
| 109 | "\n" |
| 110 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 111 | "sub_key is a string that must be a subkey of the key identified by the key parameter.\n" |
| 112 | " This value must not be None, and the key may not have subkeys.\n" |
| 113 | "\n" |
| 114 | "This method can not delete keys with subkeys.\n" |
| 115 | "\n" |
| 116 | "If the method succeeds, the entire key, including all of its values,\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 117 | "is removed. If the method fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 118 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 119 | PyDoc_STRVAR(DeleteValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 120 | "DeleteValue(key, value) - Removes a named value from a registry key.\n" |
| 121 | "\n" |
| 122 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 123 | "value is a string that identifies the value to remove."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 124 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 125 | PyDoc_STRVAR(EnumKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 126 | "string = EnumKey(key, index) - Enumerates subkeys of an open registry key.\n" |
| 127 | "\n" |
| 128 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 129 | "index is an integer that identifies the index of the key to retrieve.\n" |
| 130 | "\n" |
| 131 | "The function retrieves the name of one subkey each time it is called.\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 132 | "It is typically called repeatedly until an EnvironmentError exception is\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 133 | "raised, indicating no more values are available."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 134 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 135 | PyDoc_STRVAR(EnumValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 136 | "tuple = EnumValue(key, index) - Enumerates values of an open registry key.\n" |
| 137 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 138 | "index is an integer that identifies the index of the value to retrieve.\n" |
| 139 | "\n" |
| 140 | "The function retrieves the name of one subkey each time it is called.\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 141 | "It is typically called repeatedly, until an EnvironmentError exception\n" |
| 142 | "is raised, indicating no more values.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 143 | "\n" |
| 144 | "The result is a tuple of 3 items:\n" |
| 145 | "value_name is a string that identifies the value.\n" |
| 146 | "value_data is an object that holds the value data, and whose type depends\n" |
| 147 | " on the underlying registry type.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 148 | "data_type is an integer that identifies the type of the value data."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 149 | |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 150 | PyDoc_STRVAR(ExpandEnvironmentStrings_doc, |
| 151 | "string = ExpandEnvironmentStrings(string) - Expand environment vars.\n"); |
| 152 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 153 | PyDoc_STRVAR(FlushKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 154 | "FlushKey(key) - Writes all the attributes of a key to the registry.\n" |
| 155 | "\n" |
| 156 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 157 | "\n" |
| 158 | "It is not necessary to call RegFlushKey to change a key.\n" |
| 159 | "Registry changes are flushed to disk by the registry using its lazy flusher.\n" |
| 160 | "Registry changes are also flushed to disk at system shutdown.\n" |
| 161 | "Unlike CloseKey(), the FlushKey() method returns only when all the data has\n" |
| 162 | "been written to the registry.\n" |
| 163 | "An application should only call FlushKey() if it requires absolute certainty that registry changes are on disk.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 164 | "If you don't know whether a FlushKey() call is required, it probably isn't."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 165 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 166 | PyDoc_STRVAR(LoadKey_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 167 | "LoadKey(key, sub_key, file_name) - Creates a subkey under the specified key\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 168 | "and stores registration information from a specified file into that subkey.\n" |
| 169 | "\n" |
| 170 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 171 | "sub_key is a string that identifies the sub_key to load\n" |
| 172 | "file_name is the name of the file to load registry data from.\n" |
| 173 | " This file must have been created with the SaveKey() function.\n" |
| 174 | " Under the file allocation table (FAT) file system, the filename may not\n" |
| 175 | "have an extension.\n" |
| 176 | "\n" |
| 177 | "A call to LoadKey() fails if the calling process does not have the\n" |
| 178 | "SE_RESTORE_PRIVILEGE privilege.\n" |
| 179 | "\n" |
| 180 | "If key is a handle returned by ConnectRegistry(), then the path specified\n" |
| 181 | "in fileName is relative to the remote computer.\n" |
| 182 | "\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 183 | "The docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE tree"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 184 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 185 | PyDoc_STRVAR(OpenKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 186 | "key = OpenKey(key, sub_key, res = 0, sam = KEY_READ) - Opens the specified key.\n" |
| 187 | "\n" |
| 188 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 189 | "sub_key is a string that identifies the sub_key to open\n" |
| 190 | "res is a reserved integer, and must be zero. Default is zero.\n" |
| 191 | "sam is an integer that specifies an access mask that describes the desired\n" |
| 192 | " security access for the key. Default is KEY_READ\n" |
| 193 | "\n" |
| 194 | "The result is a new handle to the specified key\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 195 | "If the function fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 196 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 197 | PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 198 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 199 | PyDoc_STRVAR(QueryInfoKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 200 | "tuple = QueryInfoKey(key) - Returns information about a key.\n" |
| 201 | "\n" |
| 202 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 203 | "\n" |
| 204 | "The result is a tuple of 3 items:" |
| 205 | "An integer that identifies the number of sub keys this key has.\n" |
| 206 | "An integer that identifies the number of values this key has.\n" |
| 207 | "A long integer that identifies when the key was last modified (if available)\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 208 | " as 100's of nanoseconds since Jan 1, 1600."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 209 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 210 | PyDoc_STRVAR(QueryValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 211 | "string = QueryValue(key, sub_key) - retrieves the unnamed value for a key.\n" |
| 212 | "\n" |
| 213 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 214 | "sub_key is a string that holds the name of the subkey with which the value\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 215 | " is associated. If this parameter is None or empty, the function retrieves\n" |
| 216 | " the value set by the SetValue() method for the key identified by key." |
| 217 | "\n" |
| 218 | "Values in the registry have name, type, and data components. This method\n" |
| 219 | "retrieves the data for a key's first value that has a NULL name.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 220 | "But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE THIS!!!"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 221 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 222 | PyDoc_STRVAR(QueryValueEx_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 223 | "value,type_id = QueryValueEx(key, value_name) - Retrieves the type and data for a specified value name associated with an open registry key.\n" |
| 224 | "\n" |
| 225 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 226 | "value_name is a string indicating the value to query"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 227 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 228 | PyDoc_STRVAR(SaveKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 229 | "SaveKey(key, file_name) - Saves the specified key, and all its subkeys to the specified file.\n" |
| 230 | "\n" |
| 231 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 232 | "file_name is the name of the file to save registry data to.\n" |
| 233 | " This file cannot already exist. If this filename includes an extension,\n" |
| 234 | " it cannot be used on file allocation table (FAT) file systems by the\n" |
| 235 | " LoadKey(), ReplaceKey() or RestoreKey() methods.\n" |
| 236 | "\n" |
| 237 | "If key represents a key on a remote computer, the path described by\n" |
| 238 | "file_name is relative to the remote computer.\n" |
| 239 | "The caller of this method must possess the SeBackupPrivilege security privilege.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 240 | "This function passes NULL for security_attributes to the API."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 241 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 242 | PyDoc_STRVAR(SetValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 243 | "SetValue(key, sub_key, type, value) - Associates a value with a specified key.\n" |
| 244 | "\n" |
| 245 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
| 246 | "sub_key is a string that names the subkey with which the value is associated.\n" |
| 247 | "type is an integer that specifies the type of the data. Currently this\n" |
| 248 | " must be REG_SZ, meaning only strings are supported.\n" |
| 249 | "value is a string that specifies the new value.\n" |
| 250 | "\n" |
| 251 | "If the key specified by the sub_key parameter does not exist, the SetValue\n" |
| 252 | "function creates it.\n" |
| 253 | "\n" |
| 254 | "Value lengths are limited by available memory. Long values (more than\n" |
| 255 | "2048 bytes) should be stored as files with the filenames stored in \n" |
| 256 | "the configuration registry. This helps the registry perform efficiently.\n" |
| 257 | "\n" |
| 258 | "The key identified by the key parameter must have been opened with\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 259 | "KEY_SET_VALUE access."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 260 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 261 | PyDoc_STRVAR(SetValueEx_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 262 | "SetValueEx(key, value_name, reserved, type, value) - Stores data in the value field of an open registry key.\n" |
| 263 | "\n" |
| 264 | "key is an already open key, or any one of the predefined HKEY_* constants.\n" |
Mark Hammond | c9083b6 | 2003-01-15 23:38:15 +0000 | [diff] [blame] | 265 | "value_name is a string containing the name of the value to set, or None\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 266 | "type is an integer that specifies the type of the data. This should be one of:\n" |
| 267 | " REG_BINARY -- Binary data in any form.\n" |
| 268 | " REG_DWORD -- A 32-bit number.\n" |
| 269 | " REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n" |
| 270 | " REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n" |
| 271 | " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references\n" |
| 272 | " to environment variables (for example, %PATH%).\n" |
| 273 | " REG_LINK -- A Unicode symbolic link.\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 274 | " REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n" |
| 275 | " two null characters. Note that Python handles this\n" |
| 276 | " termination automatically.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 277 | " REG_NONE -- No defined value type.\n" |
| 278 | " REG_RESOURCE_LIST -- A device-driver resource list.\n" |
| 279 | " REG_SZ -- A null-terminated string.\n" |
| 280 | "reserved can be anything - zero is always passed to the API.\n" |
| 281 | "value is a string that specifies the new value.\n" |
| 282 | "\n" |
| 283 | "This method can also set additional value and type information for the\n" |
| 284 | "specified key. The key identified by the key parameter must have been\n" |
| 285 | "opened with KEY_SET_VALUE access.\n" |
| 286 | "\n" |
| 287 | "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n" |
| 288 | "\n" |
| 289 | "Value lengths are limited by available memory. Long values (more than\n" |
| 290 | "2048 bytes) should be stored as files with the filenames stored in \n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 291 | "the configuration registry. This helps the registry perform efficiently."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 292 | |
| 293 | /* PyHKEY docstrings */ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 294 | PyDoc_STRVAR(PyHKEY_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 295 | "PyHKEY Object - A Python object, representing a win32 registry key.\n" |
| 296 | "\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 297 | "This object wraps a Windows HKEY object, automatically closing it when\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 298 | "the object is destroyed. To guarantee cleanup, you can call either\n" |
| 299 | "the Close() method on the PyHKEY, or the CloseKey() method.\n" |
| 300 | "\n" |
| 301 | "All functions which accept a handle object also accept an integer - \n" |
| 302 | "however, use of the handle object is encouraged.\n" |
| 303 | "\n" |
| 304 | "Functions:\n" |
| 305 | "Close() - Closes the underlying handle.\n" |
| 306 | "Detach() - Returns the integer Win32 handle, detaching it from the object\n" |
| 307 | "\n" |
| 308 | "Properties:\n" |
| 309 | "handle - The integer Win32 handle.\n" |
| 310 | "\n" |
| 311 | "Operations:\n" |
| 312 | "__nonzero__ - Handles with an open object return true, otherwise false.\n" |
| 313 | "__int__ - Converting a handle to an integer returns the Win32 handle.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 314 | "__cmp__ - Handle objects are compared using the handle value."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 315 | |
| 316 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 317 | PyDoc_STRVAR(PyHKEY_Close_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 318 | "key.Close() - Closes the underlying Windows handle.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 319 | "\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 320 | "If the handle is already closed, no error is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 321 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 322 | PyDoc_STRVAR(PyHKEY_Detach_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 323 | "int = key.Detach() - Detaches the Windows handle from the handle object.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 324 | "\n" |
| 325 | "The result is the value of the handle before it is detached. If the\n" |
| 326 | "handle is already detached, this will return zero.\n" |
| 327 | "\n" |
| 328 | "After calling this function, the handle is effectively invalidated,\n" |
| 329 | "but the handle is not closed. You would call this function when you\n" |
| 330 | "need the underlying win32 handle to exist beyond the lifetime of the\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 331 | "handle object.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 332 | "On 64 bit windows, the result of this function is a long integer"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 333 | |
| 334 | |
| 335 | /************************************************************************ |
| 336 | |
| 337 | The PyHKEY object definition |
| 338 | |
| 339 | ************************************************************************/ |
| 340 | typedef struct { |
| 341 | PyObject_VAR_HEAD |
| 342 | HKEY hkey; |
| 343 | } PyHKEYObject; |
| 344 | |
| 345 | #define PyHKEY_Check(op) ((op)->ob_type == &PyHKEY_Type) |
| 346 | |
| 347 | static char *failMsg = "bad operand type"; |
| 348 | |
| 349 | static PyObject * |
| 350 | PyHKEY_unaryFailureFunc(PyObject *ob) |
| 351 | { |
| 352 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 353 | return NULL; |
| 354 | } |
| 355 | static PyObject * |
| 356 | PyHKEY_binaryFailureFunc(PyObject *ob1, PyObject *ob2) |
| 357 | { |
| 358 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 359 | return NULL; |
| 360 | } |
| 361 | static PyObject * |
| 362 | PyHKEY_ternaryFailureFunc(PyObject *ob1, PyObject *ob2, PyObject *ob3) |
| 363 | { |
| 364 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 365 | return NULL; |
| 366 | } |
| 367 | |
| 368 | static void |
| 369 | PyHKEY_deallocFunc(PyObject *ob) |
| 370 | { |
| 371 | /* Can not call PyHKEY_Close, as the ob->tp_type |
| 372 | has already been cleared, thus causing the type |
| 373 | check to fail! |
| 374 | */ |
| 375 | PyHKEYObject *obkey = (PyHKEYObject *)ob; |
| 376 | if (obkey->hkey) |
| 377 | RegCloseKey((HKEY)obkey->hkey); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 378 | PyObject_DEL(ob); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static int |
| 382 | PyHKEY_nonzeroFunc(PyObject *ob) |
| 383 | { |
| 384 | return ((PyHKEYObject *)ob)->hkey != 0; |
| 385 | } |
| 386 | |
| 387 | static PyObject * |
| 388 | PyHKEY_intFunc(PyObject *ob) |
| 389 | { |
| 390 | PyHKEYObject *pyhkey = (PyHKEYObject *)ob; |
| 391 | return PyLong_FromVoidPtr(pyhkey->hkey); |
| 392 | } |
| 393 | |
| 394 | static int |
| 395 | PyHKEY_printFunc(PyObject *ob, FILE *fp, int flags) |
| 396 | { |
| 397 | PyHKEYObject *pyhkey = (PyHKEYObject *)ob; |
| 398 | char resBuf[160]; |
| 399 | wsprintf(resBuf, "<PyHKEY at %p (%p)>", |
| 400 | ob, pyhkey->hkey); |
| 401 | fputs(resBuf, fp); |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static PyObject * |
| 406 | PyHKEY_strFunc(PyObject *ob) |
| 407 | { |
| 408 | PyHKEYObject *pyhkey = (PyHKEYObject *)ob; |
| 409 | char resBuf[160]; |
| 410 | wsprintf(resBuf, "<PyHKEY:%p>", pyhkey->hkey); |
| 411 | return PyString_FromString(resBuf); |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2) |
| 416 | { |
| 417 | PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1; |
| 418 | PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2; |
| 419 | return pyhkey1 == pyhkey2 ? 0 : |
| 420 | (pyhkey1 < pyhkey2 ? -1 : 1); |
| 421 | } |
| 422 | |
| 423 | static long |
| 424 | PyHKEY_hashFunc(PyObject *ob) |
| 425 | { |
| 426 | /* Just use the address. |
| 427 | XXX - should we use the handle value? |
| 428 | */ |
Fred Drake | 13634cf | 2000-06-29 19:17:04 +0000 | [diff] [blame] | 429 | return _Py_HashPointer(ob); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | |
| 433 | static PyNumberMethods PyHKEY_NumberMethods = |
| 434 | { |
| 435 | PyHKEY_binaryFailureFunc, /* nb_add */ |
| 436 | PyHKEY_binaryFailureFunc, /* nb_subtract */ |
| 437 | PyHKEY_binaryFailureFunc, /* nb_multiply */ |
| 438 | PyHKEY_binaryFailureFunc, /* nb_divide */ |
| 439 | PyHKEY_binaryFailureFunc, /* nb_remainder */ |
| 440 | PyHKEY_binaryFailureFunc, /* nb_divmod */ |
| 441 | PyHKEY_ternaryFailureFunc, /* nb_power */ |
| 442 | PyHKEY_unaryFailureFunc, /* nb_negative */ |
| 443 | PyHKEY_unaryFailureFunc, /* nb_positive */ |
| 444 | PyHKEY_unaryFailureFunc, /* nb_absolute */ |
| 445 | PyHKEY_nonzeroFunc, /* nb_nonzero */ |
| 446 | PyHKEY_unaryFailureFunc, /* nb_invert */ |
| 447 | PyHKEY_binaryFailureFunc, /* nb_lshift */ |
| 448 | PyHKEY_binaryFailureFunc, /* nb_rshift */ |
| 449 | PyHKEY_binaryFailureFunc, /* nb_and */ |
| 450 | PyHKEY_binaryFailureFunc, /* nb_xor */ |
| 451 | PyHKEY_binaryFailureFunc, /* nb_or */ |
| 452 | 0, /* nb_coerce (allowed to be zero) */ |
| 453 | PyHKEY_intFunc, /* nb_int */ |
| 454 | PyHKEY_unaryFailureFunc, /* nb_long */ |
| 455 | PyHKEY_unaryFailureFunc, /* nb_float */ |
| 456 | PyHKEY_unaryFailureFunc, /* nb_oct */ |
| 457 | PyHKEY_unaryFailureFunc, /* nb_hex */ |
| 458 | }; |
| 459 | |
| 460 | |
| 461 | /* fwd declare __getattr__ */ |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 462 | static PyObject *PyHKEY_getattr(PyObject *self, const char *name); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 463 | |
| 464 | /* The type itself */ |
| 465 | PyTypeObject PyHKEY_Type = |
| 466 | { |
Martin v. Löwis | 6819210 | 2007-07-21 06:55:02 +0000 | [diff] [blame] | 467 | PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 468 | "PyHKEY", |
| 469 | sizeof(PyHKEYObject), |
| 470 | 0, |
| 471 | PyHKEY_deallocFunc, /* tp_dealloc */ |
| 472 | PyHKEY_printFunc, /* tp_print */ |
| 473 | PyHKEY_getattr, /* tp_getattr */ |
| 474 | 0, /* tp_setattr */ |
| 475 | PyHKEY_compareFunc, /* tp_compare */ |
| 476 | 0, /* tp_repr */ |
| 477 | &PyHKEY_NumberMethods, /* tp_as_number */ |
| 478 | 0, /* tp_as_sequence */ |
| 479 | 0, /* tp_as_mapping */ |
| 480 | PyHKEY_hashFunc, /* tp_hash */ |
| 481 | 0, /* tp_call */ |
| 482 | PyHKEY_strFunc, /* tp_str */ |
| 483 | 0, /* tp_getattro */ |
| 484 | 0, /* tp_setattro */ |
| 485 | 0, /* tp_as_buffer */ |
| 486 | 0, /* tp_flags */ |
| 487 | PyHKEY_doc, /* tp_doc */ |
| 488 | }; |
| 489 | |
| 490 | #define OFF(e) offsetof(PyHKEYObject, e) |
| 491 | |
| 492 | static struct memberlist PyHKEY_memberlist[] = { |
| 493 | {"handle", T_INT, OFF(hkey)}, |
| 494 | {NULL} /* Sentinel */ |
| 495 | }; |
| 496 | |
| 497 | /************************************************************************ |
| 498 | |
| 499 | The PyHKEY object methods |
| 500 | |
| 501 | ************************************************************************/ |
| 502 | static PyObject * |
| 503 | PyHKEY_CloseMethod(PyObject *self, PyObject *args) |
| 504 | { |
| 505 | if (!PyArg_ParseTuple(args, ":Close")) |
| 506 | return NULL; |
| 507 | if (!PyHKEY_Close(self)) |
| 508 | return NULL; |
| 509 | Py_INCREF(Py_None); |
| 510 | return Py_None; |
| 511 | } |
| 512 | |
| 513 | static PyObject * |
| 514 | PyHKEY_DetachMethod(PyObject *self, PyObject *args) |
| 515 | { |
| 516 | void* ret; |
| 517 | PyHKEYObject *pThis = (PyHKEYObject *)self; |
| 518 | if (!PyArg_ParseTuple(args, ":Detach")) |
| 519 | return NULL; |
| 520 | ret = (void*)pThis->hkey; |
| 521 | pThis->hkey = 0; |
| 522 | return PyLong_FromVoidPtr(ret); |
| 523 | } |
| 524 | |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 525 | static PyObject * |
| 526 | PyHKEY_Enter(PyObject *self) |
| 527 | { |
| 528 | Py_XINCREF(self); |
| 529 | return self; |
| 530 | } |
| 531 | |
| 532 | static PyObject * |
| 533 | PyHKEY_Exit(PyObject *self, PyObject *args) |
| 534 | { |
| 535 | if (!PyHKEY_Close(self)) |
| 536 | return NULL; |
| 537 | Py_RETURN_NONE; |
| 538 | } |
| 539 | |
| 540 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 541 | static struct PyMethodDef PyHKEY_methods[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 542 | {"Close", PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc}, |
| 543 | {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc}, |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 544 | {"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL}, |
| 545 | {"__exit__", PyHKEY_Exit, METH_VARARGS, NULL}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 546 | {NULL} |
| 547 | }; |
| 548 | |
| 549 | /*static*/ PyObject * |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 550 | PyHKEY_getattr(PyObject *self, const char *name) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 551 | { |
| 552 | PyObject *res; |
| 553 | |
| 554 | res = Py_FindMethod(PyHKEY_methods, self, name); |
| 555 | if (res != NULL) |
| 556 | return res; |
| 557 | PyErr_Clear(); |
| 558 | if (strcmp(name, "handle") == 0) |
| 559 | return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey); |
| 560 | return PyMember_Get((char *)self, PyHKEY_memberlist, name); |
| 561 | } |
| 562 | |
| 563 | /************************************************************************ |
| 564 | The public PyHKEY API (well, not public yet :-) |
| 565 | ************************************************************************/ |
| 566 | PyObject * |
| 567 | PyHKEY_New(HKEY hInit) |
| 568 | { |
| 569 | PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type); |
| 570 | if (key) |
| 571 | key->hkey = hInit; |
| 572 | return (PyObject *)key; |
| 573 | } |
| 574 | |
| 575 | BOOL |
| 576 | PyHKEY_Close(PyObject *ob_handle) |
| 577 | { |
| 578 | LONG rc; |
| 579 | PyHKEYObject *key; |
| 580 | |
| 581 | if (!PyHKEY_Check(ob_handle)) { |
| 582 | PyErr_SetString(PyExc_TypeError, "bad operand type"); |
| 583 | return FALSE; |
| 584 | } |
| 585 | key = (PyHKEYObject *)ob_handle; |
| 586 | rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS; |
| 587 | key->hkey = 0; |
| 588 | if (rc != ERROR_SUCCESS) |
| 589 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 590 | return rc == ERROR_SUCCESS; |
| 591 | } |
| 592 | |
| 593 | BOOL |
| 594 | PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK) |
| 595 | { |
| 596 | if (ob == Py_None) { |
| 597 | if (!bNoneOK) { |
| 598 | PyErr_SetString( |
| 599 | PyExc_TypeError, |
| 600 | "None is not a valid HKEY in this context"); |
| 601 | return FALSE; |
| 602 | } |
| 603 | *pHANDLE = (HKEY)0; |
| 604 | } |
| 605 | else if (PyHKEY_Check(ob)) { |
| 606 | PyHKEYObject *pH = (PyHKEYObject *)ob; |
| 607 | *pHANDLE = pH->hkey; |
| 608 | } |
| 609 | else if (PyInt_Check(ob) || PyLong_Check(ob)) { |
| 610 | /* We also support integers */ |
| 611 | PyErr_Clear(); |
| 612 | *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob); |
| 613 | if (PyErr_Occurred()) |
| 614 | return FALSE; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 615 | } |
| 616 | else { |
| 617 | PyErr_SetString( |
| 618 | PyExc_TypeError, |
| 619 | "The object is not a PyHKEY object"); |
| 620 | return FALSE; |
| 621 | } |
| 622 | return TRUE; |
| 623 | } |
| 624 | |
| 625 | PyObject * |
| 626 | PyHKEY_FromHKEY(HKEY h) |
| 627 | { |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 628 | PyHKEYObject *op; |
| 629 | |
Guido van Rossum | e3a8e7e | 2002-08-19 19:26:42 +0000 | [diff] [blame] | 630 | /* Inline PyObject_New */ |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 631 | op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 632 | if (op == NULL) |
| 633 | return PyErr_NoMemory(); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 634 | PyObject_INIT(op, &PyHKEY_Type); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 635 | op->hkey = h; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 636 | return (PyObject *)op; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /************************************************************************ |
| 641 | The module methods |
| 642 | ************************************************************************/ |
| 643 | BOOL |
| 644 | PyWinObject_CloseHKEY(PyObject *obHandle) |
| 645 | { |
| 646 | BOOL ok; |
| 647 | if (PyHKEY_Check(obHandle)) { |
| 648 | ok = PyHKEY_Close(obHandle); |
| 649 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 650 | #if SIZEOF_LONG >= SIZEOF_HKEY |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 651 | else if (PyInt_Check(obHandle)) { |
| 652 | long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle)); |
| 653 | ok = (rc == ERROR_SUCCESS); |
| 654 | if (!ok) |
| 655 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 656 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 657 | #else |
| 658 | else if (PyLong_Check(obHandle)) { |
| 659 | long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle)); |
| 660 | ok = (rc == ERROR_SUCCESS); |
| 661 | if (!ok) |
| 662 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 663 | } |
| 664 | #endif |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 665 | else { |
| 666 | PyErr_SetString( |
| 667 | PyExc_TypeError, |
| 668 | "A handle must be a HKEY object or an integer"); |
| 669 | return FALSE; |
| 670 | } |
| 671 | return ok; |
| 672 | } |
| 673 | |
| 674 | |
| 675 | /* |
| 676 | Private Helper functions for the registry interfaces |
| 677 | |
| 678 | ** Note that fixupMultiSZ and countString have both had changes |
| 679 | ** made to support "incorrect strings". The registry specification |
| 680 | ** calls for strings to be terminated with 2 null bytes. It seems |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 681 | ** some commercial packages install strings which dont conform, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 682 | ** causing this code to fail - however, "regedit" etc still work |
| 683 | ** with these strings (ie only we dont!). |
| 684 | */ |
| 685 | static void |
| 686 | fixupMultiSZ(char **str, char *data, int len) |
| 687 | { |
| 688 | char *P; |
| 689 | int i; |
| 690 | char *Q; |
| 691 | |
| 692 | Q = data + len; |
| 693 | for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) { |
| 694 | str[i] = P; |
| 695 | for(; *P != '\0'; P++) |
| 696 | ; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | static int |
| 701 | countStrings(char *data, int len) |
| 702 | { |
| 703 | int strings; |
| 704 | char *P; |
| 705 | char *Q = data + len; |
| 706 | |
| 707 | for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++) |
| 708 | for (; P < Q && *P != '\0'; P++) |
| 709 | ; |
| 710 | return strings; |
| 711 | } |
| 712 | |
| 713 | /* Convert PyObject into Registry data. |
| 714 | Allocates space as needed. */ |
| 715 | static BOOL |
| 716 | Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) |
| 717 | { |
| 718 | int i,j; |
| 719 | switch (typ) { |
| 720 | case REG_DWORD: |
| 721 | if (value != Py_None && !PyInt_Check(value)) |
| 722 | return FALSE; |
Kristján Valur Jónsson | 17b8e97 | 2007-04-25 00:10:50 +0000 | [diff] [blame] | 723 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 724 | if (*retDataBuf==NULL){ |
| 725 | PyErr_NoMemory(); |
| 726 | return FALSE; |
| 727 | } |
| 728 | *retDataSize = sizeof(DWORD); |
| 729 | if (value == Py_None) { |
| 730 | DWORD zero = 0; |
| 731 | memcpy(*retDataBuf, &zero, sizeof(DWORD)); |
| 732 | } |
| 733 | else |
| 734 | memcpy(*retDataBuf, |
| 735 | &PyInt_AS_LONG((PyIntObject *)value), |
| 736 | sizeof(DWORD)); |
| 737 | break; |
| 738 | case REG_SZ: |
| 739 | case REG_EXPAND_SZ: |
| 740 | { |
| 741 | int need_decref = 0; |
| 742 | if (value == Py_None) |
| 743 | *retDataSize = 1; |
| 744 | else { |
| 745 | if (PyUnicode_Check(value)) { |
| 746 | value = PyUnicode_AsEncodedString( |
| 747 | value, |
| 748 | "mbcs", |
| 749 | NULL); |
| 750 | if (value==NULL) |
| 751 | return FALSE; |
| 752 | need_decref = 1; |
| 753 | } |
| 754 | if (!PyString_Check(value)) |
| 755 | return FALSE; |
| 756 | *retDataSize = 1 + strlen( |
| 757 | PyString_AS_STRING( |
| 758 | (PyStringObject *)value)); |
| 759 | } |
| 760 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize); |
| 761 | if (*retDataBuf==NULL){ |
| 762 | PyErr_NoMemory(); |
| 763 | return FALSE; |
| 764 | } |
| 765 | if (value == Py_None) |
| 766 | strcpy((char *)*retDataBuf, ""); |
| 767 | else |
| 768 | strcpy((char *)*retDataBuf, |
| 769 | PyString_AS_STRING( |
| 770 | (PyStringObject *)value)); |
| 771 | if (need_decref) |
| 772 | Py_DECREF(value); |
| 773 | break; |
| 774 | } |
| 775 | case REG_MULTI_SZ: |
| 776 | { |
| 777 | DWORD size = 0; |
| 778 | char *P; |
| 779 | PyObject **obs = NULL; |
| 780 | |
| 781 | if (value == Py_None) |
| 782 | i = 0; |
| 783 | else { |
| 784 | if (!PyList_Check(value)) |
| 785 | return FALSE; |
| 786 | i = PyList_Size(value); |
| 787 | } |
| 788 | obs = malloc(sizeof(PyObject *) * i); |
| 789 | memset(obs, 0, sizeof(PyObject *) * i); |
| 790 | for (j = 0; j < i; j++) |
| 791 | { |
| 792 | PyObject *t; |
| 793 | t = PyList_GET_ITEM( |
| 794 | (PyListObject *)value,j); |
| 795 | if (PyString_Check(t)) { |
| 796 | obs[j] = t; |
| 797 | Py_INCREF(t); |
| 798 | } else if (PyUnicode_Check(t)) { |
| 799 | obs[j] = PyUnicode_AsEncodedString( |
| 800 | t, |
| 801 | "mbcs", |
| 802 | NULL); |
| 803 | if (obs[j]==NULL) |
| 804 | goto reg_multi_fail; |
| 805 | } else |
| 806 | goto reg_multi_fail; |
| 807 | size += 1 + strlen( |
| 808 | PyString_AS_STRING( |
| 809 | (PyStringObject *)obs[j])); |
| 810 | } |
| 811 | |
| 812 | *retDataSize = size + 1; |
| 813 | *retDataBuf = (BYTE *)PyMem_NEW(char, |
| 814 | *retDataSize); |
| 815 | if (*retDataBuf==NULL){ |
| 816 | PyErr_NoMemory(); |
| 817 | goto reg_multi_fail; |
| 818 | } |
| 819 | P = (char *)*retDataBuf; |
| 820 | |
| 821 | for (j = 0; j < i; j++) |
| 822 | { |
| 823 | PyObject *t; |
| 824 | t = obs[j]; |
| 825 | strcpy(P, |
| 826 | PyString_AS_STRING( |
| 827 | (PyStringObject *)t)); |
| 828 | P += 1 + strlen( |
| 829 | PyString_AS_STRING( |
| 830 | (PyStringObject *)t)); |
| 831 | Py_DECREF(obs[j]); |
| 832 | } |
| 833 | /* And doubly-terminate the list... */ |
| 834 | *P = '\0'; |
| 835 | free(obs); |
| 836 | break; |
| 837 | reg_multi_fail: |
| 838 | if (obs) { |
| 839 | for (j = 0; j < i; j++) |
| 840 | Py_XDECREF(obs[j]); |
| 841 | |
| 842 | free(obs); |
| 843 | } |
| 844 | return FALSE; |
| 845 | } |
| 846 | case REG_BINARY: |
| 847 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 848 | support it natively, we should handle the bits. */ |
| 849 | default: |
| 850 | if (value == Py_None) |
| 851 | *retDataSize = 0; |
| 852 | else { |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 853 | void *src_buf; |
| 854 | PyBufferProcs *pb = value->ob_type->tp_as_buffer; |
| 855 | if (pb==NULL) { |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 856 | PyErr_Format(PyExc_TypeError, |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 857 | "Objects of type '%s' can not " |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 858 | "be used as binary registry values", |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 859 | value->ob_type->tp_name); |
| 860 | return FALSE; |
| 861 | } |
| 862 | *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 863 | *retDataBuf = (BYTE *)PyMem_NEW(char, |
| 864 | *retDataSize); |
| 865 | if (*retDataBuf==NULL){ |
| 866 | PyErr_NoMemory(); |
| 867 | return FALSE; |
| 868 | } |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 869 | memcpy(*retDataBuf, src_buf, *retDataSize); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 870 | } |
| 871 | break; |
| 872 | } |
| 873 | return TRUE; |
| 874 | } |
| 875 | |
| 876 | /* Convert Registry data into PyObject*/ |
| 877 | static PyObject * |
| 878 | Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ) |
| 879 | { |
| 880 | PyObject *obData; |
| 881 | |
| 882 | switch (typ) { |
| 883 | case REG_DWORD: |
| 884 | if (retDataSize == 0) |
| 885 | obData = Py_BuildValue("i", 0); |
| 886 | else |
| 887 | obData = Py_BuildValue("i", |
| 888 | *(int *)retDataBuf); |
| 889 | break; |
| 890 | case REG_SZ: |
| 891 | case REG_EXPAND_SZ: |
| 892 | /* retDataBuf may or may not have a trailing NULL in |
| 893 | the buffer. */ |
| 894 | if (retDataSize && retDataBuf[retDataSize-1] == '\0') |
| 895 | --retDataSize; |
| 896 | if (retDataSize ==0) |
| 897 | retDataBuf = ""; |
| 898 | obData = PyUnicode_DecodeMBCS(retDataBuf, |
| 899 | retDataSize, |
| 900 | NULL); |
| 901 | break; |
| 902 | case REG_MULTI_SZ: |
| 903 | if (retDataSize == 0) |
| 904 | obData = PyList_New(0); |
| 905 | else |
| 906 | { |
| 907 | int index = 0; |
| 908 | int s = countStrings(retDataBuf, retDataSize); |
| 909 | char **str = (char **)malloc(sizeof(char *)*s); |
| 910 | if (str == NULL) |
| 911 | return PyErr_NoMemory(); |
| 912 | |
| 913 | fixupMultiSZ(str, retDataBuf, retDataSize); |
| 914 | obData = PyList_New(s); |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 915 | if (obData == NULL) |
| 916 | return NULL; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 917 | for (index = 0; index < s; index++) |
| 918 | { |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 919 | size_t len = _mbstrlen(str[index]); |
| 920 | if (len > INT_MAX) { |
| 921 | PyErr_SetString(PyExc_OverflowError, |
| 922 | "registry string is too long for a Python string"); |
| 923 | Py_DECREF(obData); |
| 924 | return NULL; |
| 925 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 926 | PyList_SetItem(obData, |
| 927 | index, |
| 928 | PyUnicode_DecodeMBCS( |
| 929 | (const char *)str[index], |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 930 | (int)len, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 931 | NULL) |
| 932 | ); |
| 933 | } |
| 934 | free(str); |
| 935 | |
| 936 | break; |
| 937 | } |
| 938 | case REG_BINARY: |
| 939 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 940 | support it natively, we should handle the bits. */ |
| 941 | default: |
| 942 | if (retDataSize == 0) { |
| 943 | Py_INCREF(Py_None); |
| 944 | obData = Py_None; |
| 945 | } |
| 946 | else |
| 947 | obData = Py_BuildValue("s#", |
| 948 | (char *)retDataBuf, |
| 949 | retDataSize); |
| 950 | break; |
| 951 | } |
| 952 | if (obData == NULL) |
| 953 | return NULL; |
| 954 | else |
| 955 | return obData; |
| 956 | } |
| 957 | |
| 958 | /* The Python methods */ |
| 959 | |
| 960 | static PyObject * |
| 961 | PyCloseKey(PyObject *self, PyObject *args) |
| 962 | { |
| 963 | PyObject *obKey; |
| 964 | if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey)) |
| 965 | return NULL; |
| 966 | if (!PyHKEY_Close(obKey)) |
| 967 | return NULL; |
| 968 | Py_INCREF(Py_None); |
| 969 | return Py_None; |
| 970 | } |
| 971 | |
| 972 | static PyObject * |
| 973 | PyConnectRegistry(PyObject *self, PyObject *args) |
| 974 | { |
| 975 | HKEY hKey; |
| 976 | PyObject *obKey; |
| 977 | char *szCompName = NULL; |
| 978 | HKEY retKey; |
| 979 | long rc; |
| 980 | if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey)) |
| 981 | return NULL; |
| 982 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 983 | return NULL; |
Martin v. Löwis | bda0dde | 2006-07-24 10:26:33 +0000 | [diff] [blame] | 984 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 985 | rc = RegConnectRegistry(szCompName, hKey, &retKey); |
Martin v. Löwis | bda0dde | 2006-07-24 10:26:33 +0000 | [diff] [blame] | 986 | Py_END_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 987 | if (rc != ERROR_SUCCESS) |
| 988 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 989 | "ConnectRegistry"); |
| 990 | return PyHKEY_FromHKEY(retKey); |
| 991 | } |
| 992 | |
| 993 | static PyObject * |
| 994 | PyCreateKey(PyObject *self, PyObject *args) |
| 995 | { |
| 996 | HKEY hKey; |
| 997 | PyObject *obKey; |
| 998 | char *subKey; |
| 999 | HKEY retKey; |
| 1000 | long rc; |
| 1001 | if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey)) |
| 1002 | return NULL; |
| 1003 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1004 | return NULL; |
| 1005 | rc = RegCreateKey(hKey, subKey, &retKey); |
| 1006 | if (rc != ERROR_SUCCESS) |
| 1007 | return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); |
| 1008 | return PyHKEY_FromHKEY(retKey); |
| 1009 | } |
| 1010 | |
| 1011 | static PyObject * |
| 1012 | PyDeleteKey(PyObject *self, PyObject *args) |
| 1013 | { |
| 1014 | HKEY hKey; |
| 1015 | PyObject *obKey; |
| 1016 | char *subKey; |
| 1017 | long rc; |
| 1018 | if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey)) |
| 1019 | return NULL; |
| 1020 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1021 | return NULL; |
| 1022 | rc = RegDeleteKey(hKey, subKey ); |
| 1023 | if (rc != ERROR_SUCCESS) |
| 1024 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); |
| 1025 | Py_INCREF(Py_None); |
| 1026 | return Py_None; |
| 1027 | } |
| 1028 | |
| 1029 | static PyObject * |
| 1030 | PyDeleteValue(PyObject *self, PyObject *args) |
| 1031 | { |
| 1032 | HKEY hKey; |
| 1033 | PyObject *obKey; |
| 1034 | char *subKey; |
| 1035 | long rc; |
| 1036 | if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey)) |
| 1037 | return NULL; |
| 1038 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1039 | return NULL; |
| 1040 | Py_BEGIN_ALLOW_THREADS |
| 1041 | rc = RegDeleteValue(hKey, subKey); |
| 1042 | Py_END_ALLOW_THREADS |
| 1043 | if (rc !=ERROR_SUCCESS) |
| 1044 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1045 | "RegDeleteValue"); |
| 1046 | Py_INCREF(Py_None); |
| 1047 | return Py_None; |
| 1048 | } |
| 1049 | |
| 1050 | static PyObject * |
| 1051 | PyEnumKey(PyObject *self, PyObject *args) |
| 1052 | { |
| 1053 | HKEY hKey; |
| 1054 | PyObject *obKey; |
| 1055 | int index; |
| 1056 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1057 | PyObject *retStr; |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1058 | char tmpbuf[256]; /* max key name length is 255 */ |
Georg Brandl | b2699b2 | 2006-02-18 23:44:24 +0000 | [diff] [blame] | 1059 | DWORD len = sizeof(tmpbuf); /* includes NULL terminator */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1060 | |
| 1061 | if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) |
| 1062 | return NULL; |
| 1063 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1064 | return NULL; |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1065 | |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1066 | Py_BEGIN_ALLOW_THREADS |
| 1067 | rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL); |
| 1068 | Py_END_ALLOW_THREADS |
| 1069 | if (rc != ERROR_SUCCESS) |
| 1070 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx"); |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1071 | |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1072 | retStr = PyString_FromStringAndSize(tmpbuf, len); |
| 1073 | return retStr; /* can be NULL */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static PyObject * |
| 1077 | PyEnumValue(PyObject *self, PyObject *args) |
| 1078 | { |
| 1079 | HKEY hKey; |
| 1080 | PyObject *obKey; |
| 1081 | int index; |
| 1082 | long rc; |
| 1083 | char *retValueBuf; |
| 1084 | char *retDataBuf; |
| 1085 | DWORD retValueSize; |
| 1086 | DWORD retDataSize; |
| 1087 | DWORD typ; |
| 1088 | PyObject *obData; |
| 1089 | PyObject *retVal; |
| 1090 | |
| 1091 | if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) |
| 1092 | return NULL; |
| 1093 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1094 | return NULL; |
| 1095 | |
| 1096 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, |
| 1097 | NULL, |
| 1098 | &retValueSize, &retDataSize, NULL, NULL)) |
| 1099 | != ERROR_SUCCESS) |
| 1100 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1101 | "RegQueryInfoKey"); |
| 1102 | ++retValueSize; /* include null terminators */ |
| 1103 | ++retDataSize; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1104 | retValueBuf = (char *)PyMem_Malloc(retValueSize); |
| 1105 | if (retValueBuf == NULL) |
| 1106 | return PyErr_NoMemory(); |
| 1107 | retDataBuf = (char *)PyMem_Malloc(retDataSize); |
| 1108 | if (retDataBuf == NULL) { |
| 1109 | PyMem_Free(retValueBuf); |
| 1110 | return PyErr_NoMemory(); |
| 1111 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1112 | |
| 1113 | Py_BEGIN_ALLOW_THREADS |
| 1114 | rc = RegEnumValue(hKey, |
| 1115 | index, |
| 1116 | retValueBuf, |
| 1117 | &retValueSize, |
| 1118 | NULL, |
| 1119 | &typ, |
| 1120 | (BYTE *)retDataBuf, |
| 1121 | &retDataSize); |
| 1122 | Py_END_ALLOW_THREADS |
| 1123 | |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1124 | if (rc != ERROR_SUCCESS) { |
| 1125 | retVal = PyErr_SetFromWindowsErrWithFunction(rc, |
| 1126 | "PyRegEnumValue"); |
| 1127 | goto fail; |
| 1128 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1129 | obData = Reg2Py(retDataBuf, retDataSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1130 | if (obData == NULL) { |
| 1131 | retVal = NULL; |
| 1132 | goto fail; |
| 1133 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1134 | retVal = Py_BuildValue("sOi", retValueBuf, obData, typ); |
| 1135 | Py_DECREF(obData); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1136 | fail: |
| 1137 | PyMem_Free(retValueBuf); |
| 1138 | PyMem_Free(retDataBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1139 | return retVal; |
| 1140 | } |
| 1141 | |
| 1142 | static PyObject * |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 1143 | PyExpandEnvironmentStrings(PyObject *self, PyObject *args) |
| 1144 | { |
| 1145 | Py_UNICODE *retValue = NULL; |
| 1146 | Py_UNICODE *src; |
| 1147 | DWORD retValueSize; |
| 1148 | DWORD rc; |
| 1149 | PyObject *o; |
| 1150 | |
| 1151 | if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src)) |
| 1152 | return NULL; |
| 1153 | |
| 1154 | retValueSize = ExpandEnvironmentStringsW(src, retValue, 0); |
| 1155 | if (retValueSize == 0) { |
| 1156 | return PyErr_SetFromWindowsErrWithFunction(retValueSize, |
| 1157 | "ExpandEnvironmentStrings"); |
| 1158 | } |
| 1159 | retValue = (Py_UNICODE *)PyMem_Malloc(retValueSize * sizeof(Py_UNICODE)); |
| 1160 | if (retValue == NULL) { |
| 1161 | return PyErr_NoMemory(); |
| 1162 | } |
| 1163 | |
| 1164 | rc = ExpandEnvironmentStringsW(src, retValue, retValueSize); |
| 1165 | if (rc == 0) { |
| 1166 | PyMem_Free(retValue); |
| 1167 | return PyErr_SetFromWindowsErrWithFunction(retValueSize, |
| 1168 | "ExpandEnvironmentStrings"); |
| 1169 | } |
| 1170 | o = PyUnicode_FromUnicode(retValue, wcslen(retValue)); |
| 1171 | PyMem_Free(retValue); |
| 1172 | return o; |
| 1173 | } |
| 1174 | |
| 1175 | static PyObject * |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1176 | PyFlushKey(PyObject *self, PyObject *args) |
| 1177 | { |
| 1178 | HKEY hKey; |
| 1179 | PyObject *obKey; |
| 1180 | long rc; |
| 1181 | if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey)) |
| 1182 | return NULL; |
| 1183 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1184 | return NULL; |
| 1185 | Py_BEGIN_ALLOW_THREADS |
| 1186 | rc = RegFlushKey(hKey); |
| 1187 | Py_END_ALLOW_THREADS |
| 1188 | if (rc != ERROR_SUCCESS) |
| 1189 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); |
| 1190 | Py_INCREF(Py_None); |
| 1191 | return Py_None; |
| 1192 | } |
| 1193 | static PyObject * |
| 1194 | PyLoadKey(PyObject *self, PyObject *args) |
| 1195 | { |
| 1196 | HKEY hKey; |
| 1197 | PyObject *obKey; |
| 1198 | char *subKey; |
| 1199 | char *fileName; |
| 1200 | |
| 1201 | long rc; |
| 1202 | if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName)) |
| 1203 | return NULL; |
| 1204 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1205 | return NULL; |
| 1206 | Py_BEGIN_ALLOW_THREADS |
| 1207 | rc = RegLoadKey(hKey, subKey, fileName ); |
| 1208 | Py_END_ALLOW_THREADS |
| 1209 | if (rc != ERROR_SUCCESS) |
| 1210 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); |
| 1211 | Py_INCREF(Py_None); |
| 1212 | return Py_None; |
| 1213 | } |
| 1214 | |
| 1215 | static PyObject * |
| 1216 | PyOpenKey(PyObject *self, PyObject *args) |
| 1217 | { |
| 1218 | HKEY hKey; |
| 1219 | PyObject *obKey; |
| 1220 | |
| 1221 | char *subKey; |
| 1222 | int res = 0; |
| 1223 | HKEY retKey; |
| 1224 | long rc; |
| 1225 | REGSAM sam = KEY_READ; |
| 1226 | if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey, |
| 1227 | &res, &sam)) |
| 1228 | return NULL; |
| 1229 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1230 | return NULL; |
| 1231 | |
| 1232 | Py_BEGIN_ALLOW_THREADS |
| 1233 | rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey); |
| 1234 | Py_END_ALLOW_THREADS |
| 1235 | if (rc != ERROR_SUCCESS) |
| 1236 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); |
| 1237 | return PyHKEY_FromHKEY(retKey); |
| 1238 | } |
| 1239 | |
| 1240 | |
| 1241 | static PyObject * |
| 1242 | PyQueryInfoKey(PyObject *self, PyObject *args) |
| 1243 | { |
| 1244 | HKEY hKey; |
| 1245 | PyObject *obKey; |
| 1246 | long rc; |
| 1247 | DWORD nSubKeys, nValues; |
| 1248 | FILETIME ft; |
| 1249 | LARGE_INTEGER li; |
| 1250 | PyObject *l; |
| 1251 | PyObject *ret; |
| 1252 | if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey)) |
| 1253 | return NULL; |
| 1254 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1255 | return NULL; |
| 1256 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL, |
| 1257 | &nValues, NULL, NULL, NULL, &ft)) |
| 1258 | != ERROR_SUCCESS) |
| 1259 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey"); |
| 1260 | li.LowPart = ft.dwLowDateTime; |
| 1261 | li.HighPart = ft.dwHighDateTime; |
| 1262 | l = PyLong_FromLongLong(li.QuadPart); |
| 1263 | if (l == NULL) |
| 1264 | return NULL; |
| 1265 | ret = Py_BuildValue("iiO", nSubKeys, nValues, l); |
| 1266 | Py_DECREF(l); |
| 1267 | return ret; |
| 1268 | } |
| 1269 | |
| 1270 | static PyObject * |
| 1271 | PyQueryValue(PyObject *self, PyObject *args) |
| 1272 | { |
| 1273 | HKEY hKey; |
| 1274 | PyObject *obKey; |
| 1275 | char *subKey; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1276 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1277 | PyObject *retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1278 | char *retBuf; |
| 1279 | long bufSize = 0; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1280 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1281 | if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey)) |
| 1282 | return NULL; |
| 1283 | |
| 1284 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1285 | return NULL; |
| 1286 | if ((rc = RegQueryValue(hKey, subKey, NULL, &bufSize)) |
| 1287 | != ERROR_SUCCESS) |
| 1288 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1289 | "RegQueryValue"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1290 | retStr = PyString_FromStringAndSize(NULL, bufSize); |
| 1291 | if (retStr == NULL) |
| 1292 | return NULL; |
| 1293 | retBuf = PyString_AS_STRING(retStr); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1294 | if ((rc = RegQueryValue(hKey, subKey, retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1295 | != ERROR_SUCCESS) { |
| 1296 | Py_DECREF(retStr); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1297 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1298 | "RegQueryValue"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1299 | } |
| 1300 | _PyString_Resize(&retStr, strlen(retBuf)); |
| 1301 | return retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static PyObject * |
| 1305 | PyQueryValueEx(PyObject *self, PyObject *args) |
| 1306 | { |
| 1307 | HKEY hKey; |
| 1308 | PyObject *obKey; |
| 1309 | char *valueName; |
| 1310 | |
| 1311 | long rc; |
| 1312 | char *retBuf; |
| 1313 | DWORD bufSize = 0; |
| 1314 | DWORD typ; |
| 1315 | PyObject *obData; |
| 1316 | PyObject *result; |
| 1317 | |
| 1318 | if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName)) |
| 1319 | return NULL; |
| 1320 | |
| 1321 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1322 | return NULL; |
| 1323 | if ((rc = RegQueryValueEx(hKey, valueName, |
| 1324 | NULL, NULL, NULL, |
| 1325 | &bufSize)) |
| 1326 | != ERROR_SUCCESS) |
| 1327 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1328 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1329 | retBuf = (char *)PyMem_Malloc(bufSize); |
| 1330 | if (retBuf == NULL) |
| 1331 | return PyErr_NoMemory(); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1332 | if ((rc = RegQueryValueEx(hKey, valueName, NULL, |
| 1333 | &typ, (BYTE *)retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1334 | != ERROR_SUCCESS) { |
| 1335 | PyMem_Free(retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1336 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1337 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1338 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1339 | obData = Reg2Py(retBuf, bufSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1340 | PyMem_Free((void *)retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1341 | if (obData == NULL) |
| 1342 | return NULL; |
| 1343 | result = Py_BuildValue("Oi", obData, typ); |
| 1344 | Py_DECREF(obData); |
| 1345 | return result; |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | static PyObject * |
| 1350 | PySaveKey(PyObject *self, PyObject *args) |
| 1351 | { |
| 1352 | HKEY hKey; |
| 1353 | PyObject *obKey; |
| 1354 | char *fileName; |
| 1355 | LPSECURITY_ATTRIBUTES pSA = NULL; |
| 1356 | |
| 1357 | long rc; |
| 1358 | if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName)) |
| 1359 | return NULL; |
| 1360 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1361 | return NULL; |
| 1362 | /* One day we may get security into the core? |
| 1363 | if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE)) |
| 1364 | return NULL; |
| 1365 | */ |
| 1366 | Py_BEGIN_ALLOW_THREADS |
| 1367 | rc = RegSaveKey(hKey, fileName, pSA ); |
| 1368 | Py_END_ALLOW_THREADS |
| 1369 | if (rc != ERROR_SUCCESS) |
| 1370 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); |
| 1371 | Py_INCREF(Py_None); |
| 1372 | return Py_None; |
| 1373 | } |
| 1374 | |
| 1375 | static PyObject * |
| 1376 | PySetValue(PyObject *self, PyObject *args) |
| 1377 | { |
| 1378 | HKEY hKey; |
| 1379 | PyObject *obKey; |
| 1380 | char *subKey; |
| 1381 | char *str; |
| 1382 | DWORD typ; |
| 1383 | DWORD len; |
| 1384 | long rc; |
| 1385 | PyObject *obStrVal; |
| 1386 | PyObject *obSubKey; |
| 1387 | if (!PyArg_ParseTuple(args, "OOiO:SetValue", |
| 1388 | &obKey, |
| 1389 | &obSubKey, |
| 1390 | &typ, |
| 1391 | &obStrVal)) |
| 1392 | return NULL; |
| 1393 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1394 | return NULL; |
| 1395 | if (typ != REG_SZ) { |
| 1396 | PyErr_SetString(PyExc_TypeError, |
Thomas Heller | e1d18f5 | 2002-12-20 20:13:35 +0000 | [diff] [blame] | 1397 | "Type must be _winreg.REG_SZ"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1398 | return NULL; |
| 1399 | } |
| 1400 | /* XXX - need Unicode support */ |
| 1401 | str = PyString_AsString(obStrVal); |
| 1402 | if (str == NULL) |
| 1403 | return NULL; |
| 1404 | len = PyString_Size(obStrVal); |
| 1405 | if (obSubKey == Py_None) |
| 1406 | subKey = NULL; |
| 1407 | else { |
| 1408 | subKey = PyString_AsString(obSubKey); |
| 1409 | if (subKey == NULL) |
| 1410 | return NULL; |
| 1411 | } |
| 1412 | Py_BEGIN_ALLOW_THREADS |
| 1413 | rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1); |
| 1414 | Py_END_ALLOW_THREADS |
| 1415 | if (rc != ERROR_SUCCESS) |
| 1416 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); |
| 1417 | Py_INCREF(Py_None); |
| 1418 | return Py_None; |
| 1419 | } |
| 1420 | |
| 1421 | static PyObject * |
| 1422 | PySetValueEx(PyObject *self, PyObject *args) |
| 1423 | { |
| 1424 | HKEY hKey; |
| 1425 | PyObject *obKey; |
| 1426 | char *valueName; |
| 1427 | PyObject *obRes; |
| 1428 | PyObject *value; |
| 1429 | BYTE *data; |
| 1430 | DWORD len; |
| 1431 | DWORD typ; |
| 1432 | |
| 1433 | LONG rc; |
| 1434 | |
| 1435 | if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx", |
| 1436 | &obKey, |
| 1437 | &valueName, |
| 1438 | &obRes, |
| 1439 | &typ, |
| 1440 | &value)) |
| 1441 | return NULL; |
| 1442 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1443 | return NULL; |
| 1444 | if (!Py2Reg(value, typ, &data, &len)) |
| 1445 | { |
| 1446 | if (!PyErr_Occurred()) |
| 1447 | PyErr_SetString(PyExc_ValueError, |
| 1448 | "Could not convert the data to the specified type."); |
| 1449 | return NULL; |
| 1450 | } |
| 1451 | Py_BEGIN_ALLOW_THREADS |
| 1452 | rc = RegSetValueEx(hKey, valueName, 0, typ, data, len); |
| 1453 | Py_END_ALLOW_THREADS |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 1454 | PyMem_DEL(data); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1455 | if (rc != ERROR_SUCCESS) |
| 1456 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1457 | "RegSetValueEx"); |
| 1458 | Py_INCREF(Py_None); |
| 1459 | return Py_None; |
| 1460 | } |
| 1461 | |
| 1462 | static struct PyMethodDef winreg_methods[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 1463 | {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, |
| 1464 | {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, |
| 1465 | {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, |
| 1466 | {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, |
| 1467 | {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, |
| 1468 | {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, |
| 1469 | {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, |
Christian Heimes | b39a756 | 2008-01-08 15:46:10 +0000 | [diff] [blame] | 1470 | {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS, |
| 1471 | ExpandEnvironmentStrings_doc }, |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 1472 | {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc}, |
| 1473 | {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc}, |
| 1474 | {"OpenKey", PyOpenKey, METH_VARARGS, OpenKey_doc}, |
| 1475 | {"OpenKeyEx", PyOpenKey, METH_VARARGS, OpenKeyEx_doc}, |
| 1476 | {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc}, |
| 1477 | {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc}, |
| 1478 | {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc}, |
| 1479 | {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc}, |
| 1480 | {"SetValue", PySetValue, METH_VARARGS, SetValue_doc}, |
| 1481 | {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1482 | NULL, |
| 1483 | }; |
| 1484 | |
| 1485 | static void |
| 1486 | insint(PyObject * d, char * name, long value) |
| 1487 | { |
| 1488 | PyObject *v = PyInt_FromLong(value); |
| 1489 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1490 | PyErr_Clear(); |
| 1491 | Py_XDECREF(v); |
| 1492 | } |
| 1493 | |
| 1494 | #define ADD_INT(val) insint(d, #val, val) |
| 1495 | |
| 1496 | static void |
| 1497 | inskey(PyObject * d, char * name, HKEY key) |
| 1498 | { |
| 1499 | PyObject *v = PyLong_FromVoidPtr(key); |
| 1500 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1501 | PyErr_Clear(); |
| 1502 | Py_XDECREF(v); |
| 1503 | } |
| 1504 | |
| 1505 | #define ADD_KEY(val) inskey(d, #val, val) |
| 1506 | |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 1507 | PyMODINIT_FUNC init_winreg(void) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1508 | { |
| 1509 | PyObject *m, *d; |
Fred Drake | 270e19b | 2000-06-29 16:14:14 +0000 | [diff] [blame] | 1510 | m = Py_InitModule3("_winreg", winreg_methods, module_doc); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 1511 | if (m == NULL) |
| 1512 | return; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1513 | d = PyModule_GetDict(m); |
| 1514 | PyHKEY_Type.ob_type = &PyType_Type; |
| 1515 | PyHKEY_Type.tp_doc = PyHKEY_doc; |
| 1516 | Py_INCREF(&PyHKEY_Type); |
| 1517 | if (PyDict_SetItemString(d, "HKEYType", |
| 1518 | (PyObject *)&PyHKEY_Type) != 0) |
| 1519 | return; |
| 1520 | Py_INCREF(PyExc_WindowsError); |
| 1521 | if (PyDict_SetItemString(d, "error", |
| 1522 | PyExc_WindowsError) != 0) |
| 1523 | return; |
| 1524 | |
| 1525 | /* Add the relevant constants */ |
| 1526 | ADD_KEY(HKEY_CLASSES_ROOT); |
| 1527 | ADD_KEY(HKEY_CURRENT_USER); |
| 1528 | ADD_KEY(HKEY_LOCAL_MACHINE); |
| 1529 | ADD_KEY(HKEY_USERS); |
| 1530 | ADD_KEY(HKEY_PERFORMANCE_DATA); |
| 1531 | #ifdef HKEY_CURRENT_CONFIG |
| 1532 | ADD_KEY(HKEY_CURRENT_CONFIG); |
| 1533 | #endif |
| 1534 | #ifdef HKEY_DYN_DATA |
| 1535 | ADD_KEY(HKEY_DYN_DATA); |
| 1536 | #endif |
| 1537 | ADD_INT(KEY_QUERY_VALUE); |
| 1538 | ADD_INT(KEY_SET_VALUE); |
| 1539 | ADD_INT(KEY_CREATE_SUB_KEY); |
| 1540 | ADD_INT(KEY_ENUMERATE_SUB_KEYS); |
| 1541 | ADD_INT(KEY_NOTIFY); |
| 1542 | ADD_INT(KEY_CREATE_LINK); |
| 1543 | ADD_INT(KEY_READ); |
| 1544 | ADD_INT(KEY_WRITE); |
| 1545 | ADD_INT(KEY_EXECUTE); |
| 1546 | ADD_INT(KEY_ALL_ACCESS); |
| 1547 | ADD_INT(REG_OPTION_RESERVED); |
| 1548 | ADD_INT(REG_OPTION_NON_VOLATILE); |
| 1549 | ADD_INT(REG_OPTION_VOLATILE); |
| 1550 | ADD_INT(REG_OPTION_CREATE_LINK); |
| 1551 | ADD_INT(REG_OPTION_BACKUP_RESTORE); |
| 1552 | ADD_INT(REG_OPTION_OPEN_LINK); |
| 1553 | ADD_INT(REG_LEGAL_OPTION); |
| 1554 | ADD_INT(REG_CREATED_NEW_KEY); |
| 1555 | ADD_INT(REG_OPENED_EXISTING_KEY); |
| 1556 | ADD_INT(REG_WHOLE_HIVE_VOLATILE); |
| 1557 | ADD_INT(REG_REFRESH_HIVE); |
| 1558 | ADD_INT(REG_NO_LAZY_FLUSH); |
| 1559 | ADD_INT(REG_NOTIFY_CHANGE_NAME); |
| 1560 | ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES); |
| 1561 | ADD_INT(REG_NOTIFY_CHANGE_LAST_SET); |
| 1562 | ADD_INT(REG_NOTIFY_CHANGE_SECURITY); |
| 1563 | ADD_INT(REG_LEGAL_CHANGE_FILTER); |
| 1564 | ADD_INT(REG_NONE); |
| 1565 | ADD_INT(REG_SZ); |
| 1566 | ADD_INT(REG_EXPAND_SZ); |
| 1567 | ADD_INT(REG_BINARY); |
| 1568 | ADD_INT(REG_DWORD); |
| 1569 | ADD_INT(REG_DWORD_LITTLE_ENDIAN); |
| 1570 | ADD_INT(REG_DWORD_BIG_ENDIAN); |
| 1571 | ADD_INT(REG_LINK); |
| 1572 | ADD_INT(REG_MULTI_SZ); |
| 1573 | ADD_INT(REG_RESOURCE_LIST); |
| 1574 | ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR); |
| 1575 | ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); |
| 1576 | } |
| 1577 | |