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 */ |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +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" |
| 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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 71 | "to see what constants are used, and where."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 72 | |
| 73 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 74 | PyDoc_STRVAR(CloseKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 75 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 80 | "closed when the hkey object is destroyed by Python."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 81 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 82 | PyDoc_STRVAR(ConnectRegistry_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 83 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 91 | "If the function fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 92 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 93 | PyDoc_STRVAR(CreateKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 94 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 104 | "If the function fails, an exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 105 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 106 | PyDoc_STRVAR(DeleteKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 107 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 116 | "is removed. If the method fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 117 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 118 | PyDoc_STRVAR(DeleteValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 119 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 122 | "value is a string that identifies the value to remove."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 123 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 124 | PyDoc_STRVAR(EnumKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 125 | "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 Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 131 | "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] | 132 | "raised, indicating no more values are available."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 133 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 134 | PyDoc_STRVAR(EnumValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 135 | "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 Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 140 | "It is typically called repeatedly, until an EnvironmentError exception\n" |
| 141 | "is raised, indicating no more values.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 142 | "\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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 147 | "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] | 148 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 149 | PyDoc_STRVAR(FlushKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 150 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 160 | "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] | 161 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 162 | PyDoc_STRVAR(LoadKey_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 163 | "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] | 164 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 179 | "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] | 180 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 181 | PyDoc_STRVAR(OpenKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 182 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 191 | "If the function fails, an EnvironmentError exception is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 192 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 193 | PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 194 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 195 | PyDoc_STRVAR(QueryInfoKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 196 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 204 | " as 100's of nanoseconds since Jan 1, 1600."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 205 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 206 | PyDoc_STRVAR(QueryValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 207 | "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 Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 210 | "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] | 211 | " 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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 216 | "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] | 217 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 218 | PyDoc_STRVAR(QueryValueEx_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 219 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 222 | "value_name is a string indicating the value to query"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 223 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 224 | PyDoc_STRVAR(SaveKey_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 225 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 236 | "This function passes NULL for security_attributes to the API."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 237 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 238 | PyDoc_STRVAR(SetValue_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 239 | "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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 255 | "KEY_SET_VALUE access."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 256 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 257 | PyDoc_STRVAR(SetValueEx_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 258 | "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 Hammond | c9083b6 | 2003-01-15 23:38:15 +0000 | [diff] [blame] | 261 | "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] | 262 | "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 Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 270 | " 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 Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 273 | " 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öwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 287 | "the configuration registry. This helps the registry perform efficiently."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 288 | |
| 289 | /* PyHKEY docstrings */ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 290 | PyDoc_STRVAR(PyHKEY_doc, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 291 | "PyHKEY Object - A Python object, representing a win32 registry key.\n" |
| 292 | "\n" |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 293 | "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] | 294 | "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 Diederich | 4dafcc4 | 2006-11-28 19:15:13 +0000 | [diff] [blame] | 308 | "__bool__ - Handles with an open object return true, otherwise false.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 309 | "__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] | 310 | "__cmp__ - Handle objects are compared using the handle value."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 311 | |
| 312 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 313 | PyDoc_STRVAR(PyHKEY_Close_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 314 | "key.Close() - Closes the underlying Windows handle.\n" |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 315 | "\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 316 | "If the handle is already closed, no error is raised."); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 317 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 318 | PyDoc_STRVAR(PyHKEY_Detach_doc, |
Mark Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 319 | "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] | 320 | "\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 Hammond | b422f95 | 2000-06-09 06:01:47 +0000 | [diff] [blame] | 327 | "handle object.\n" |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 328 | "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] | 329 | |
| 330 | |
| 331 | /************************************************************************ |
| 332 | |
| 333 | The PyHKEY object definition |
| 334 | |
| 335 | ************************************************************************/ |
| 336 | typedef struct { |
| 337 | PyObject_VAR_HEAD |
| 338 | HKEY hkey; |
| 339 | } PyHKEYObject; |
| 340 | |
| 341 | #define PyHKEY_Check(op) ((op)->ob_type == &PyHKEY_Type) |
| 342 | |
| 343 | static char *failMsg = "bad operand type"; |
| 344 | |
| 345 | static PyObject * |
| 346 | PyHKEY_unaryFailureFunc(PyObject *ob) |
| 347 | { |
| 348 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 349 | return NULL; |
| 350 | } |
| 351 | static PyObject * |
| 352 | PyHKEY_binaryFailureFunc(PyObject *ob1, PyObject *ob2) |
| 353 | { |
| 354 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 355 | return NULL; |
| 356 | } |
| 357 | static PyObject * |
| 358 | PyHKEY_ternaryFailureFunc(PyObject *ob1, PyObject *ob2, PyObject *ob3) |
| 359 | { |
| 360 | PyErr_SetString(PyExc_TypeError, failMsg); |
| 361 | return NULL; |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | PyHKEY_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 Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 374 | PyObject_DEL(ob); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static int |
Jack Diederich | 4dafcc4 | 2006-11-28 19:15:13 +0000 | [diff] [blame] | 378 | PyHKEY_boolFunc(PyObject *ob) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 379 | { |
| 380 | return ((PyHKEYObject *)ob)->hkey != 0; |
| 381 | } |
| 382 | |
| 383 | static PyObject * |
| 384 | PyHKEY_intFunc(PyObject *ob) |
| 385 | { |
| 386 | PyHKEYObject *pyhkey = (PyHKEYObject *)ob; |
| 387 | return PyLong_FromVoidPtr(pyhkey->hkey); |
| 388 | } |
| 389 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 390 | static PyObject * |
| 391 | PyHKEY_strFunc(PyObject *ob) |
| 392 | { |
| 393 | PyHKEYObject *pyhkey = (PyHKEYObject *)ob; |
| 394 | char resBuf[160]; |
| 395 | wsprintf(resBuf, "<PyHKEY:%p>", pyhkey->hkey); |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 396 | return PyUnicode_FromString(resBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static int |
| 400 | PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2) |
| 401 | { |
| 402 | PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1; |
| 403 | PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2; |
| 404 | return pyhkey1 == pyhkey2 ? 0 : |
| 405 | (pyhkey1 < pyhkey2 ? -1 : 1); |
| 406 | } |
| 407 | |
| 408 | static long |
| 409 | PyHKEY_hashFunc(PyObject *ob) |
| 410 | { |
| 411 | /* Just use the address. |
| 412 | XXX - should we use the handle value? |
| 413 | */ |
Fred Drake | 13634cf | 2000-06-29 19:17:04 +0000 | [diff] [blame] | 414 | return _Py_HashPointer(ob); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
| 418 | static PyNumberMethods PyHKEY_NumberMethods = |
| 419 | { |
| 420 | PyHKEY_binaryFailureFunc, /* nb_add */ |
| 421 | PyHKEY_binaryFailureFunc, /* nb_subtract */ |
| 422 | PyHKEY_binaryFailureFunc, /* nb_multiply */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 423 | PyHKEY_binaryFailureFunc, /* nb_remainder */ |
| 424 | PyHKEY_binaryFailureFunc, /* nb_divmod */ |
| 425 | PyHKEY_ternaryFailureFunc, /* nb_power */ |
| 426 | PyHKEY_unaryFailureFunc, /* nb_negative */ |
| 427 | PyHKEY_unaryFailureFunc, /* nb_positive */ |
| 428 | PyHKEY_unaryFailureFunc, /* nb_absolute */ |
Jack Diederich | 4dafcc4 | 2006-11-28 19:15:13 +0000 | [diff] [blame] | 429 | PyHKEY_boolFunc, /* nb_bool */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 430 | PyHKEY_unaryFailureFunc, /* nb_invert */ |
| 431 | PyHKEY_binaryFailureFunc, /* nb_lshift */ |
| 432 | PyHKEY_binaryFailureFunc, /* nb_rshift */ |
| 433 | PyHKEY_binaryFailureFunc, /* nb_and */ |
| 434 | PyHKEY_binaryFailureFunc, /* nb_xor */ |
| 435 | PyHKEY_binaryFailureFunc, /* nb_or */ |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 436 | NULL, /* nb_coerce */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 437 | PyHKEY_intFunc, /* nb_int */ |
| 438 | PyHKEY_unaryFailureFunc, /* nb_long */ |
| 439 | PyHKEY_unaryFailureFunc, /* nb_float */ |
| 440 | PyHKEY_unaryFailureFunc, /* nb_oct */ |
| 441 | PyHKEY_unaryFailureFunc, /* nb_hex */ |
| 442 | }; |
| 443 | |
| 444 | |
| 445 | /* fwd declare __getattr__ */ |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 446 | static PyObject *PyHKEY_getattr(PyObject *self, const char *name); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 447 | |
| 448 | /* The type itself */ |
| 449 | PyTypeObject PyHKEY_Type = |
| 450 | { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 451 | PyVarObject_HEAD_INIT(0, 0) /* fill in type at module init */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 452 | "PyHKEY", |
| 453 | sizeof(PyHKEYObject), |
| 454 | 0, |
| 455 | PyHKEY_deallocFunc, /* tp_dealloc */ |
Guido van Rossum | 346f1a8 | 2007-08-07 19:58:47 +0000 | [diff] [blame^] | 456 | 0, /* tp_print */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 457 | PyHKEY_getattr, /* tp_getattr */ |
| 458 | 0, /* tp_setattr */ |
| 459 | PyHKEY_compareFunc, /* tp_compare */ |
| 460 | 0, /* tp_repr */ |
| 461 | &PyHKEY_NumberMethods, /* tp_as_number */ |
| 462 | 0, /* tp_as_sequence */ |
| 463 | 0, /* tp_as_mapping */ |
| 464 | PyHKEY_hashFunc, /* tp_hash */ |
| 465 | 0, /* tp_call */ |
| 466 | PyHKEY_strFunc, /* tp_str */ |
| 467 | 0, /* tp_getattro */ |
| 468 | 0, /* tp_setattro */ |
| 469 | 0, /* tp_as_buffer */ |
| 470 | 0, /* tp_flags */ |
| 471 | PyHKEY_doc, /* tp_doc */ |
| 472 | }; |
| 473 | |
| 474 | #define OFF(e) offsetof(PyHKEYObject, e) |
| 475 | |
| 476 | static struct memberlist PyHKEY_memberlist[] = { |
| 477 | {"handle", T_INT, OFF(hkey)}, |
| 478 | {NULL} /* Sentinel */ |
| 479 | }; |
| 480 | |
| 481 | /************************************************************************ |
| 482 | |
| 483 | The PyHKEY object methods |
| 484 | |
| 485 | ************************************************************************/ |
| 486 | static PyObject * |
| 487 | PyHKEY_CloseMethod(PyObject *self, PyObject *args) |
| 488 | { |
| 489 | if (!PyArg_ParseTuple(args, ":Close")) |
| 490 | return NULL; |
| 491 | if (!PyHKEY_Close(self)) |
| 492 | return NULL; |
| 493 | Py_INCREF(Py_None); |
| 494 | return Py_None; |
| 495 | } |
| 496 | |
| 497 | static PyObject * |
| 498 | PyHKEY_DetachMethod(PyObject *self, PyObject *args) |
| 499 | { |
| 500 | void* ret; |
| 501 | PyHKEYObject *pThis = (PyHKEYObject *)self; |
| 502 | if (!PyArg_ParseTuple(args, ":Detach")) |
| 503 | return NULL; |
| 504 | ret = (void*)pThis->hkey; |
| 505 | pThis->hkey = 0; |
| 506 | return PyLong_FromVoidPtr(ret); |
| 507 | } |
| 508 | |
| 509 | static struct PyMethodDef PyHKEY_methods[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 510 | {"Close", PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc}, |
| 511 | {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 512 | {NULL} |
| 513 | }; |
| 514 | |
| 515 | /*static*/ PyObject * |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 516 | PyHKEY_getattr(PyObject *self, const char *name) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 517 | { |
| 518 | PyObject *res; |
| 519 | |
| 520 | res = Py_FindMethod(PyHKEY_methods, self, name); |
| 521 | if (res != NULL) |
| 522 | return res; |
| 523 | PyErr_Clear(); |
| 524 | if (strcmp(name, "handle") == 0) |
| 525 | return PyLong_FromVoidPtr(((PyHKEYObject *)self)->hkey); |
| 526 | return PyMember_Get((char *)self, PyHKEY_memberlist, name); |
| 527 | } |
| 528 | |
| 529 | /************************************************************************ |
| 530 | The public PyHKEY API (well, not public yet :-) |
| 531 | ************************************************************************/ |
| 532 | PyObject * |
| 533 | PyHKEY_New(HKEY hInit) |
| 534 | { |
| 535 | PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type); |
| 536 | if (key) |
| 537 | key->hkey = hInit; |
| 538 | return (PyObject *)key; |
| 539 | } |
| 540 | |
| 541 | BOOL |
| 542 | PyHKEY_Close(PyObject *ob_handle) |
| 543 | { |
| 544 | LONG rc; |
| 545 | PyHKEYObject *key; |
| 546 | |
| 547 | if (!PyHKEY_Check(ob_handle)) { |
| 548 | PyErr_SetString(PyExc_TypeError, "bad operand type"); |
| 549 | return FALSE; |
| 550 | } |
| 551 | key = (PyHKEYObject *)ob_handle; |
| 552 | rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS; |
| 553 | key->hkey = 0; |
| 554 | if (rc != ERROR_SUCCESS) |
| 555 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 556 | return rc == ERROR_SUCCESS; |
| 557 | } |
| 558 | |
| 559 | BOOL |
| 560 | PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK) |
| 561 | { |
| 562 | if (ob == Py_None) { |
| 563 | if (!bNoneOK) { |
| 564 | PyErr_SetString( |
| 565 | PyExc_TypeError, |
| 566 | "None is not a valid HKEY in this context"); |
| 567 | return FALSE; |
| 568 | } |
| 569 | *pHANDLE = (HKEY)0; |
| 570 | } |
| 571 | else if (PyHKEY_Check(ob)) { |
| 572 | PyHKEYObject *pH = (PyHKEYObject *)ob; |
| 573 | *pHANDLE = pH->hkey; |
| 574 | } |
| 575 | else if (PyInt_Check(ob) || PyLong_Check(ob)) { |
| 576 | /* We also support integers */ |
| 577 | PyErr_Clear(); |
| 578 | *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob); |
| 579 | if (PyErr_Occurred()) |
| 580 | return FALSE; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 581 | } |
| 582 | else { |
| 583 | PyErr_SetString( |
| 584 | PyExc_TypeError, |
| 585 | "The object is not a PyHKEY object"); |
| 586 | return FALSE; |
| 587 | } |
| 588 | return TRUE; |
| 589 | } |
| 590 | |
| 591 | PyObject * |
| 592 | PyHKEY_FromHKEY(HKEY h) |
| 593 | { |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 594 | PyHKEYObject *op; |
| 595 | |
Guido van Rossum | e3a8e7e | 2002-08-19 19:26:42 +0000 | [diff] [blame] | 596 | /* Inline PyObject_New */ |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 597 | op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 598 | if (op == NULL) |
| 599 | return PyErr_NoMemory(); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 600 | PyObject_INIT(op, &PyHKEY_Type); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 601 | op->hkey = h; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 602 | return (PyObject *)op; |
| 603 | } |
| 604 | |
| 605 | |
| 606 | /************************************************************************ |
| 607 | The module methods |
| 608 | ************************************************************************/ |
| 609 | BOOL |
| 610 | PyWinObject_CloseHKEY(PyObject *obHandle) |
| 611 | { |
| 612 | BOOL ok; |
| 613 | if (PyHKEY_Check(obHandle)) { |
| 614 | ok = PyHKEY_Close(obHandle); |
| 615 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 616 | #if SIZEOF_LONG >= SIZEOF_HKEY |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 617 | else if (PyInt_Check(obHandle)) { |
| 618 | long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle)); |
| 619 | ok = (rc == ERROR_SUCCESS); |
| 620 | if (!ok) |
| 621 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 622 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 623 | #else |
| 624 | else if (PyLong_Check(obHandle)) { |
| 625 | long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle)); |
| 626 | ok = (rc == ERROR_SUCCESS); |
| 627 | if (!ok) |
| 628 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 629 | } |
| 630 | #endif |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 631 | else { |
| 632 | PyErr_SetString( |
| 633 | PyExc_TypeError, |
| 634 | "A handle must be a HKEY object or an integer"); |
| 635 | return FALSE; |
| 636 | } |
| 637 | return ok; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | /* |
| 642 | Private Helper functions for the registry interfaces |
| 643 | |
| 644 | ** Note that fixupMultiSZ and countString have both had changes |
| 645 | ** made to support "incorrect strings". The registry specification |
| 646 | ** calls for strings to be terminated with 2 null bytes. It seems |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 647 | ** some commercial packages install strings which dont conform, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 648 | ** causing this code to fail - however, "regedit" etc still work |
| 649 | ** with these strings (ie only we dont!). |
| 650 | */ |
| 651 | static void |
| 652 | fixupMultiSZ(char **str, char *data, int len) |
| 653 | { |
| 654 | char *P; |
| 655 | int i; |
| 656 | char *Q; |
| 657 | |
| 658 | Q = data + len; |
| 659 | for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) { |
| 660 | str[i] = P; |
| 661 | for(; *P != '\0'; P++) |
| 662 | ; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | static int |
| 667 | countStrings(char *data, int len) |
| 668 | { |
| 669 | int strings; |
| 670 | char *P; |
| 671 | char *Q = data + len; |
| 672 | |
| 673 | for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++) |
| 674 | for (; P < Q && *P != '\0'; P++) |
| 675 | ; |
| 676 | return strings; |
| 677 | } |
| 678 | |
| 679 | /* Convert PyObject into Registry data. |
| 680 | Allocates space as needed. */ |
| 681 | static BOOL |
| 682 | Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) |
| 683 | { |
| 684 | int i,j; |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 685 | DWORD d; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 686 | switch (typ) { |
| 687 | case REG_DWORD: |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 688 | if (value != Py_None && !PyLong_Check(value)) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 689 | return FALSE; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 690 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 691 | if (*retDataBuf==NULL){ |
| 692 | PyErr_NoMemory(); |
| 693 | return FALSE; |
| 694 | } |
| 695 | *retDataSize = sizeof(DWORD); |
| 696 | if (value == Py_None) { |
| 697 | DWORD zero = 0; |
| 698 | memcpy(*retDataBuf, &zero, sizeof(DWORD)); |
| 699 | } |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 700 | else { |
| 701 | d = PyLong_AsLong(value); |
| 702 | memcpy(*retDataBuf, &d, sizeof(DWORD)); |
| 703 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 704 | break; |
| 705 | case REG_SZ: |
| 706 | case REG_EXPAND_SZ: |
| 707 | { |
| 708 | int need_decref = 0; |
| 709 | if (value == Py_None) |
| 710 | *retDataSize = 1; |
| 711 | else { |
| 712 | if (PyUnicode_Check(value)) { |
| 713 | value = PyUnicode_AsEncodedString( |
| 714 | value, |
| 715 | "mbcs", |
| 716 | NULL); |
| 717 | if (value==NULL) |
| 718 | return FALSE; |
| 719 | need_decref = 1; |
| 720 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 721 | if (!PyBytes_Check(value)) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 722 | return FALSE; |
| 723 | *retDataSize = 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 724 | PyBytes_AS_STRING(value)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 725 | } |
| 726 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize); |
| 727 | if (*retDataBuf==NULL){ |
| 728 | PyErr_NoMemory(); |
| 729 | return FALSE; |
| 730 | } |
| 731 | if (value == Py_None) |
| 732 | strcpy((char *)*retDataBuf, ""); |
| 733 | else |
| 734 | strcpy((char *)*retDataBuf, |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 735 | PyBytes_AS_STRING(value)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 736 | if (need_decref) |
| 737 | Py_DECREF(value); |
| 738 | break; |
| 739 | } |
| 740 | case REG_MULTI_SZ: |
| 741 | { |
| 742 | DWORD size = 0; |
| 743 | char *P; |
| 744 | PyObject **obs = NULL; |
| 745 | |
| 746 | if (value == Py_None) |
| 747 | i = 0; |
| 748 | else { |
| 749 | if (!PyList_Check(value)) |
| 750 | return FALSE; |
| 751 | i = PyList_Size(value); |
| 752 | } |
| 753 | obs = malloc(sizeof(PyObject *) * i); |
| 754 | memset(obs, 0, sizeof(PyObject *) * i); |
| 755 | for (j = 0; j < i; j++) |
| 756 | { |
| 757 | PyObject *t; |
| 758 | t = PyList_GET_ITEM( |
| 759 | (PyListObject *)value,j); |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 760 | if (PyBytes_Check(t)) { |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 761 | obs[j] = t; |
| 762 | Py_INCREF(t); |
| 763 | } else if (PyUnicode_Check(t)) { |
| 764 | obs[j] = PyUnicode_AsEncodedString( |
| 765 | t, |
| 766 | "mbcs", |
| 767 | NULL); |
| 768 | if (obs[j]==NULL) |
| 769 | goto reg_multi_fail; |
| 770 | } else |
| 771 | goto reg_multi_fail; |
| 772 | size += 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 773 | PyBytes_AS_STRING(obs[j])); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | *retDataSize = size + 1; |
| 777 | *retDataBuf = (BYTE *)PyMem_NEW(char, |
| 778 | *retDataSize); |
| 779 | if (*retDataBuf==NULL){ |
| 780 | PyErr_NoMemory(); |
| 781 | goto reg_multi_fail; |
| 782 | } |
| 783 | P = (char *)*retDataBuf; |
| 784 | |
| 785 | for (j = 0; j < i; j++) |
| 786 | { |
| 787 | PyObject *t; |
| 788 | t = obs[j]; |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 789 | strcpy(P, PyBytes_AS_STRING(t)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 790 | P += 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 791 | PyBytes_AS_STRING(t)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 792 | Py_DECREF(obs[j]); |
| 793 | } |
| 794 | /* And doubly-terminate the list... */ |
| 795 | *P = '\0'; |
| 796 | free(obs); |
| 797 | break; |
| 798 | reg_multi_fail: |
| 799 | if (obs) { |
| 800 | for (j = 0; j < i; j++) |
| 801 | Py_XDECREF(obs[j]); |
| 802 | |
| 803 | free(obs); |
| 804 | } |
| 805 | return FALSE; |
| 806 | } |
| 807 | case REG_BINARY: |
| 808 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 809 | support it natively, we should handle the bits. */ |
| 810 | default: |
| 811 | if (value == Py_None) |
| 812 | *retDataSize = 0; |
| 813 | else { |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 814 | void *src_buf; |
| 815 | PyBufferProcs *pb = value->ob_type->tp_as_buffer; |
| 816 | if (pb==NULL) { |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 817 | PyErr_Format(PyExc_TypeError, |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 818 | "Objects of type '%s' can not " |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 819 | "be used as binary registry values", |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 820 | value->ob_type->tp_name); |
| 821 | return FALSE; |
| 822 | } |
| 823 | *retDataSize = (*pb->bf_getreadbuffer)(value, 0, &src_buf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 824 | *retDataBuf = (BYTE *)PyMem_NEW(char, |
| 825 | *retDataSize); |
| 826 | if (*retDataBuf==NULL){ |
| 827 | PyErr_NoMemory(); |
| 828 | return FALSE; |
| 829 | } |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 830 | memcpy(*retDataBuf, src_buf, *retDataSize); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 831 | } |
| 832 | break; |
| 833 | } |
| 834 | return TRUE; |
| 835 | } |
| 836 | |
| 837 | /* Convert Registry data into PyObject*/ |
| 838 | static PyObject * |
| 839 | Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ) |
| 840 | { |
| 841 | PyObject *obData; |
| 842 | |
| 843 | switch (typ) { |
| 844 | case REG_DWORD: |
| 845 | if (retDataSize == 0) |
| 846 | obData = Py_BuildValue("i", 0); |
| 847 | else |
| 848 | obData = Py_BuildValue("i", |
| 849 | *(int *)retDataBuf); |
| 850 | break; |
| 851 | case REG_SZ: |
| 852 | case REG_EXPAND_SZ: |
| 853 | /* retDataBuf may or may not have a trailing NULL in |
| 854 | the buffer. */ |
| 855 | if (retDataSize && retDataBuf[retDataSize-1] == '\0') |
| 856 | --retDataSize; |
| 857 | if (retDataSize ==0) |
| 858 | retDataBuf = ""; |
| 859 | obData = PyUnicode_DecodeMBCS(retDataBuf, |
| 860 | retDataSize, |
| 861 | NULL); |
| 862 | break; |
| 863 | case REG_MULTI_SZ: |
| 864 | if (retDataSize == 0) |
| 865 | obData = PyList_New(0); |
| 866 | else |
| 867 | { |
| 868 | int index = 0; |
| 869 | int s = countStrings(retDataBuf, retDataSize); |
| 870 | char **str = (char **)malloc(sizeof(char *)*s); |
| 871 | if (str == NULL) |
| 872 | return PyErr_NoMemory(); |
| 873 | |
| 874 | fixupMultiSZ(str, retDataBuf, retDataSize); |
| 875 | obData = PyList_New(s); |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 876 | if (obData == NULL) |
| 877 | return NULL; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 878 | for (index = 0; index < s; index++) |
| 879 | { |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 880 | size_t len = _mbstrlen(str[index]); |
| 881 | if (len > INT_MAX) { |
| 882 | PyErr_SetString(PyExc_OverflowError, |
| 883 | "registry string is too long for a Python string"); |
| 884 | Py_DECREF(obData); |
| 885 | return NULL; |
| 886 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 887 | PyList_SetItem(obData, |
| 888 | index, |
| 889 | PyUnicode_DecodeMBCS( |
| 890 | (const char *)str[index], |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 891 | (int)len, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 892 | NULL) |
| 893 | ); |
| 894 | } |
| 895 | free(str); |
| 896 | |
| 897 | break; |
| 898 | } |
| 899 | case REG_BINARY: |
| 900 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 901 | support it natively, we should handle the bits. */ |
| 902 | default: |
| 903 | if (retDataSize == 0) { |
| 904 | Py_INCREF(Py_None); |
| 905 | obData = Py_None; |
| 906 | } |
| 907 | else |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 908 | obData = Py_BuildValue("y#", |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 909 | (char *)retDataBuf, |
| 910 | retDataSize); |
| 911 | break; |
| 912 | } |
| 913 | if (obData == NULL) |
| 914 | return NULL; |
| 915 | else |
| 916 | return obData; |
| 917 | } |
| 918 | |
| 919 | /* The Python methods */ |
| 920 | |
| 921 | static PyObject * |
| 922 | PyCloseKey(PyObject *self, PyObject *args) |
| 923 | { |
| 924 | PyObject *obKey; |
| 925 | if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey)) |
| 926 | return NULL; |
| 927 | if (!PyHKEY_Close(obKey)) |
| 928 | return NULL; |
| 929 | Py_INCREF(Py_None); |
| 930 | return Py_None; |
| 931 | } |
| 932 | |
| 933 | static PyObject * |
| 934 | PyConnectRegistry(PyObject *self, PyObject *args) |
| 935 | { |
| 936 | HKEY hKey; |
| 937 | PyObject *obKey; |
| 938 | char *szCompName = NULL; |
| 939 | HKEY retKey; |
| 940 | long rc; |
| 941 | if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey)) |
| 942 | return NULL; |
| 943 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 944 | return NULL; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 945 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 946 | rc = RegConnectRegistry(szCompName, hKey, &retKey); |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 947 | Py_END_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 948 | if (rc != ERROR_SUCCESS) |
| 949 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 950 | "ConnectRegistry"); |
| 951 | return PyHKEY_FromHKEY(retKey); |
| 952 | } |
| 953 | |
| 954 | static PyObject * |
| 955 | PyCreateKey(PyObject *self, PyObject *args) |
| 956 | { |
| 957 | HKEY hKey; |
| 958 | PyObject *obKey; |
| 959 | char *subKey; |
| 960 | HKEY retKey; |
| 961 | long rc; |
| 962 | if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey)) |
| 963 | return NULL; |
| 964 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 965 | return NULL; |
| 966 | rc = RegCreateKey(hKey, subKey, &retKey); |
| 967 | if (rc != ERROR_SUCCESS) |
| 968 | return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); |
| 969 | return PyHKEY_FromHKEY(retKey); |
| 970 | } |
| 971 | |
| 972 | static PyObject * |
| 973 | PyDeleteKey(PyObject *self, PyObject *args) |
| 974 | { |
| 975 | HKEY hKey; |
| 976 | PyObject *obKey; |
| 977 | char *subKey; |
| 978 | long rc; |
| 979 | if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey)) |
| 980 | return NULL; |
| 981 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 982 | return NULL; |
| 983 | rc = RegDeleteKey(hKey, subKey ); |
| 984 | if (rc != ERROR_SUCCESS) |
| 985 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); |
| 986 | Py_INCREF(Py_None); |
| 987 | return Py_None; |
| 988 | } |
| 989 | |
| 990 | static PyObject * |
| 991 | PyDeleteValue(PyObject *self, PyObject *args) |
| 992 | { |
| 993 | HKEY hKey; |
| 994 | PyObject *obKey; |
| 995 | char *subKey; |
| 996 | long rc; |
| 997 | if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey)) |
| 998 | return NULL; |
| 999 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1000 | return NULL; |
| 1001 | Py_BEGIN_ALLOW_THREADS |
| 1002 | rc = RegDeleteValue(hKey, subKey); |
| 1003 | Py_END_ALLOW_THREADS |
| 1004 | if (rc !=ERROR_SUCCESS) |
| 1005 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1006 | "RegDeleteValue"); |
| 1007 | Py_INCREF(Py_None); |
| 1008 | return Py_None; |
| 1009 | } |
| 1010 | |
| 1011 | static PyObject * |
| 1012 | PyEnumKey(PyObject *self, PyObject *args) |
| 1013 | { |
| 1014 | HKEY hKey; |
| 1015 | PyObject *obKey; |
| 1016 | int index; |
| 1017 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1018 | PyObject *retStr; |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1019 | char tmpbuf[256]; /* max key name length is 255 */ |
Georg Brandl | b2699b2 | 2006-02-18 23:44:24 +0000 | [diff] [blame] | 1020 | DWORD len = sizeof(tmpbuf); /* includes NULL terminator */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1021 | |
| 1022 | if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) |
| 1023 | return NULL; |
| 1024 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1025 | return NULL; |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1026 | |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1027 | Py_BEGIN_ALLOW_THREADS |
| 1028 | rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL); |
| 1029 | Py_END_ALLOW_THREADS |
| 1030 | if (rc != ERROR_SUCCESS) |
| 1031 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx"); |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1032 | |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1033 | retStr = PyUnicode_FromStringAndSize(tmpbuf, len); |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1034 | return retStr; /* can be NULL */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | static PyObject * |
| 1038 | PyEnumValue(PyObject *self, PyObject *args) |
| 1039 | { |
| 1040 | HKEY hKey; |
| 1041 | PyObject *obKey; |
| 1042 | int index; |
| 1043 | long rc; |
| 1044 | char *retValueBuf; |
| 1045 | char *retDataBuf; |
| 1046 | DWORD retValueSize; |
| 1047 | DWORD retDataSize; |
| 1048 | DWORD typ; |
| 1049 | PyObject *obData; |
| 1050 | PyObject *retVal; |
| 1051 | |
| 1052 | if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) |
| 1053 | return NULL; |
| 1054 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1055 | return NULL; |
| 1056 | |
| 1057 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, |
| 1058 | NULL, |
| 1059 | &retValueSize, &retDataSize, NULL, NULL)) |
| 1060 | != ERROR_SUCCESS) |
| 1061 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1062 | "RegQueryInfoKey"); |
| 1063 | ++retValueSize; /* include null terminators */ |
| 1064 | ++retDataSize; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1065 | retValueBuf = (char *)PyMem_Malloc(retValueSize); |
| 1066 | if (retValueBuf == NULL) |
| 1067 | return PyErr_NoMemory(); |
| 1068 | retDataBuf = (char *)PyMem_Malloc(retDataSize); |
| 1069 | if (retDataBuf == NULL) { |
| 1070 | PyMem_Free(retValueBuf); |
| 1071 | return PyErr_NoMemory(); |
| 1072 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1073 | |
| 1074 | Py_BEGIN_ALLOW_THREADS |
| 1075 | rc = RegEnumValue(hKey, |
| 1076 | index, |
| 1077 | retValueBuf, |
| 1078 | &retValueSize, |
| 1079 | NULL, |
| 1080 | &typ, |
| 1081 | (BYTE *)retDataBuf, |
| 1082 | &retDataSize); |
| 1083 | Py_END_ALLOW_THREADS |
| 1084 | |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1085 | if (rc != ERROR_SUCCESS) { |
| 1086 | retVal = PyErr_SetFromWindowsErrWithFunction(rc, |
| 1087 | "PyRegEnumValue"); |
| 1088 | goto fail; |
| 1089 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1090 | obData = Reg2Py(retDataBuf, retDataSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1091 | if (obData == NULL) { |
| 1092 | retVal = NULL; |
| 1093 | goto fail; |
| 1094 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1095 | retVal = Py_BuildValue("UOi", retValueBuf, obData, typ); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1096 | Py_DECREF(obData); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1097 | fail: |
| 1098 | PyMem_Free(retValueBuf); |
| 1099 | PyMem_Free(retDataBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1100 | return retVal; |
| 1101 | } |
| 1102 | |
| 1103 | static PyObject * |
| 1104 | PyFlushKey(PyObject *self, PyObject *args) |
| 1105 | { |
| 1106 | HKEY hKey; |
| 1107 | PyObject *obKey; |
| 1108 | long rc; |
| 1109 | if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey)) |
| 1110 | return NULL; |
| 1111 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1112 | return NULL; |
| 1113 | Py_BEGIN_ALLOW_THREADS |
| 1114 | rc = RegFlushKey(hKey); |
| 1115 | Py_END_ALLOW_THREADS |
| 1116 | if (rc != ERROR_SUCCESS) |
| 1117 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); |
| 1118 | Py_INCREF(Py_None); |
| 1119 | return Py_None; |
| 1120 | } |
| 1121 | static PyObject * |
| 1122 | PyLoadKey(PyObject *self, PyObject *args) |
| 1123 | { |
| 1124 | HKEY hKey; |
| 1125 | PyObject *obKey; |
| 1126 | char *subKey; |
| 1127 | char *fileName; |
| 1128 | |
| 1129 | long rc; |
| 1130 | if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName)) |
| 1131 | return NULL; |
| 1132 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1133 | return NULL; |
| 1134 | Py_BEGIN_ALLOW_THREADS |
| 1135 | rc = RegLoadKey(hKey, subKey, fileName ); |
| 1136 | Py_END_ALLOW_THREADS |
| 1137 | if (rc != ERROR_SUCCESS) |
| 1138 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); |
| 1139 | Py_INCREF(Py_None); |
| 1140 | return Py_None; |
| 1141 | } |
| 1142 | |
| 1143 | static PyObject * |
| 1144 | PyOpenKey(PyObject *self, PyObject *args) |
| 1145 | { |
| 1146 | HKEY hKey; |
| 1147 | PyObject *obKey; |
| 1148 | |
| 1149 | char *subKey; |
| 1150 | int res = 0; |
| 1151 | HKEY retKey; |
| 1152 | long rc; |
| 1153 | REGSAM sam = KEY_READ; |
| 1154 | if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey, |
| 1155 | &res, &sam)) |
| 1156 | return NULL; |
| 1157 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1158 | return NULL; |
| 1159 | |
| 1160 | Py_BEGIN_ALLOW_THREADS |
| 1161 | rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey); |
| 1162 | Py_END_ALLOW_THREADS |
| 1163 | if (rc != ERROR_SUCCESS) |
| 1164 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); |
| 1165 | return PyHKEY_FromHKEY(retKey); |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | static PyObject * |
| 1170 | PyQueryInfoKey(PyObject *self, PyObject *args) |
| 1171 | { |
| 1172 | HKEY hKey; |
| 1173 | PyObject *obKey; |
| 1174 | long rc; |
| 1175 | DWORD nSubKeys, nValues; |
| 1176 | FILETIME ft; |
| 1177 | LARGE_INTEGER li; |
| 1178 | PyObject *l; |
| 1179 | PyObject *ret; |
| 1180 | if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey)) |
| 1181 | return NULL; |
| 1182 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1183 | return NULL; |
| 1184 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL, |
| 1185 | &nValues, NULL, NULL, NULL, &ft)) |
| 1186 | != ERROR_SUCCESS) |
| 1187 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey"); |
| 1188 | li.LowPart = ft.dwLowDateTime; |
| 1189 | li.HighPart = ft.dwHighDateTime; |
| 1190 | l = PyLong_FromLongLong(li.QuadPart); |
| 1191 | if (l == NULL) |
| 1192 | return NULL; |
| 1193 | ret = Py_BuildValue("iiO", nSubKeys, nValues, l); |
| 1194 | Py_DECREF(l); |
| 1195 | return ret; |
| 1196 | } |
| 1197 | |
| 1198 | static PyObject * |
| 1199 | PyQueryValue(PyObject *self, PyObject *args) |
| 1200 | { |
| 1201 | HKEY hKey; |
| 1202 | PyObject *obKey; |
| 1203 | char *subKey; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1204 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1205 | PyObject *retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1206 | char *retBuf; |
| 1207 | long bufSize = 0; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1208 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1209 | if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey)) |
| 1210 | return NULL; |
| 1211 | |
| 1212 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1213 | return NULL; |
| 1214 | if ((rc = RegQueryValue(hKey, subKey, NULL, &bufSize)) |
| 1215 | != ERROR_SUCCESS) |
| 1216 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1217 | "RegQueryValue"); |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1218 | retBuf = (char *)PyMem_Malloc(bufSize); |
| 1219 | if (retBuf == NULL) |
| 1220 | return PyErr_NoMemory(); |
| 1221 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1222 | if ((rc = RegQueryValue(hKey, subKey, retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1223 | != ERROR_SUCCESS) { |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1224 | PyMem_Free(retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1225 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1226 | "RegQueryValue"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1227 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1228 | |
| 1229 | retStr = PyUnicode_DecodeMBCS(retBuf, strlen(retBuf), NULL); |
| 1230 | PyMem_Free(retBuf); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1231 | return retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static PyObject * |
| 1235 | PyQueryValueEx(PyObject *self, PyObject *args) |
| 1236 | { |
| 1237 | HKEY hKey; |
| 1238 | PyObject *obKey; |
| 1239 | char *valueName; |
| 1240 | |
| 1241 | long rc; |
| 1242 | char *retBuf; |
| 1243 | DWORD bufSize = 0; |
| 1244 | DWORD typ; |
| 1245 | PyObject *obData; |
| 1246 | PyObject *result; |
| 1247 | |
| 1248 | if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName)) |
| 1249 | return NULL; |
| 1250 | |
| 1251 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1252 | return NULL; |
| 1253 | if ((rc = RegQueryValueEx(hKey, valueName, |
| 1254 | NULL, NULL, NULL, |
| 1255 | &bufSize)) |
| 1256 | != ERROR_SUCCESS) |
| 1257 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1258 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1259 | retBuf = (char *)PyMem_Malloc(bufSize); |
| 1260 | if (retBuf == NULL) |
| 1261 | return PyErr_NoMemory(); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1262 | if ((rc = RegQueryValueEx(hKey, valueName, NULL, |
| 1263 | &typ, (BYTE *)retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1264 | != ERROR_SUCCESS) { |
| 1265 | PyMem_Free(retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1266 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1267 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1268 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1269 | obData = Reg2Py(retBuf, bufSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1270 | PyMem_Free((void *)retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1271 | if (obData == NULL) |
| 1272 | return NULL; |
| 1273 | result = Py_BuildValue("Oi", obData, typ); |
| 1274 | Py_DECREF(obData); |
| 1275 | return result; |
| 1276 | } |
| 1277 | |
| 1278 | |
| 1279 | static PyObject * |
| 1280 | PySaveKey(PyObject *self, PyObject *args) |
| 1281 | { |
| 1282 | HKEY hKey; |
| 1283 | PyObject *obKey; |
| 1284 | char *fileName; |
| 1285 | LPSECURITY_ATTRIBUTES pSA = NULL; |
| 1286 | |
| 1287 | long rc; |
| 1288 | if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName)) |
| 1289 | return NULL; |
| 1290 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1291 | return NULL; |
| 1292 | /* One day we may get security into the core? |
| 1293 | if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE)) |
| 1294 | return NULL; |
| 1295 | */ |
| 1296 | Py_BEGIN_ALLOW_THREADS |
| 1297 | rc = RegSaveKey(hKey, fileName, pSA ); |
| 1298 | Py_END_ALLOW_THREADS |
| 1299 | if (rc != ERROR_SUCCESS) |
| 1300 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); |
| 1301 | Py_INCREF(Py_None); |
| 1302 | return Py_None; |
| 1303 | } |
| 1304 | |
| 1305 | static PyObject * |
| 1306 | PySetValue(PyObject *self, PyObject *args) |
| 1307 | { |
| 1308 | HKEY hKey; |
| 1309 | PyObject *obKey; |
| 1310 | char *subKey; |
| 1311 | char *str; |
| 1312 | DWORD typ; |
| 1313 | DWORD len; |
| 1314 | long rc; |
| 1315 | PyObject *obStrVal; |
| 1316 | PyObject *obSubKey; |
| 1317 | if (!PyArg_ParseTuple(args, "OOiO:SetValue", |
| 1318 | &obKey, |
| 1319 | &obSubKey, |
| 1320 | &typ, |
| 1321 | &obStrVal)) |
| 1322 | return NULL; |
| 1323 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1324 | return NULL; |
| 1325 | if (typ != REG_SZ) { |
| 1326 | PyErr_SetString(PyExc_TypeError, |
Thomas Heller | e1d18f5 | 2002-12-20 20:13:35 +0000 | [diff] [blame] | 1327 | "Type must be _winreg.REG_SZ"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1328 | return NULL; |
| 1329 | } |
| 1330 | /* XXX - need Unicode support */ |
| 1331 | str = PyString_AsString(obStrVal); |
| 1332 | if (str == NULL) |
| 1333 | return NULL; |
| 1334 | len = PyString_Size(obStrVal); |
| 1335 | if (obSubKey == Py_None) |
| 1336 | subKey = NULL; |
| 1337 | else { |
| 1338 | subKey = PyString_AsString(obSubKey); |
| 1339 | if (subKey == NULL) |
| 1340 | return NULL; |
| 1341 | } |
| 1342 | Py_BEGIN_ALLOW_THREADS |
| 1343 | rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1); |
| 1344 | Py_END_ALLOW_THREADS |
| 1345 | if (rc != ERROR_SUCCESS) |
| 1346 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); |
| 1347 | Py_INCREF(Py_None); |
| 1348 | return Py_None; |
| 1349 | } |
| 1350 | |
| 1351 | static PyObject * |
| 1352 | PySetValueEx(PyObject *self, PyObject *args) |
| 1353 | { |
| 1354 | HKEY hKey; |
| 1355 | PyObject *obKey; |
| 1356 | char *valueName; |
| 1357 | PyObject *obRes; |
| 1358 | PyObject *value; |
| 1359 | BYTE *data; |
| 1360 | DWORD len; |
| 1361 | DWORD typ; |
| 1362 | |
| 1363 | LONG rc; |
| 1364 | |
| 1365 | if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx", |
| 1366 | &obKey, |
| 1367 | &valueName, |
| 1368 | &obRes, |
| 1369 | &typ, |
| 1370 | &value)) |
| 1371 | return NULL; |
| 1372 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1373 | return NULL; |
| 1374 | if (!Py2Reg(value, typ, &data, &len)) |
| 1375 | { |
| 1376 | if (!PyErr_Occurred()) |
| 1377 | PyErr_SetString(PyExc_ValueError, |
| 1378 | "Could not convert the data to the specified type."); |
| 1379 | return NULL; |
| 1380 | } |
| 1381 | Py_BEGIN_ALLOW_THREADS |
| 1382 | rc = RegSetValueEx(hKey, valueName, 0, typ, data, len); |
| 1383 | Py_END_ALLOW_THREADS |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 1384 | PyMem_DEL(data); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1385 | if (rc != ERROR_SUCCESS) |
| 1386 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1387 | "RegSetValueEx"); |
| 1388 | Py_INCREF(Py_None); |
| 1389 | return Py_None; |
| 1390 | } |
| 1391 | |
| 1392 | static struct PyMethodDef winreg_methods[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 1393 | {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, |
| 1394 | {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, |
| 1395 | {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, |
| 1396 | {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, |
| 1397 | {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, |
| 1398 | {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, |
| 1399 | {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, |
| 1400 | {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc}, |
| 1401 | {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc}, |
| 1402 | {"OpenKey", PyOpenKey, METH_VARARGS, OpenKey_doc}, |
| 1403 | {"OpenKeyEx", PyOpenKey, METH_VARARGS, OpenKeyEx_doc}, |
| 1404 | {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc}, |
| 1405 | {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc}, |
| 1406 | {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc}, |
| 1407 | {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc}, |
| 1408 | {"SetValue", PySetValue, METH_VARARGS, SetValue_doc}, |
| 1409 | {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1410 | NULL, |
| 1411 | }; |
| 1412 | |
| 1413 | static void |
| 1414 | insint(PyObject * d, char * name, long value) |
| 1415 | { |
| 1416 | PyObject *v = PyInt_FromLong(value); |
| 1417 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1418 | PyErr_Clear(); |
| 1419 | Py_XDECREF(v); |
| 1420 | } |
| 1421 | |
| 1422 | #define ADD_INT(val) insint(d, #val, val) |
| 1423 | |
| 1424 | static void |
| 1425 | inskey(PyObject * d, char * name, HKEY key) |
| 1426 | { |
| 1427 | PyObject *v = PyLong_FromVoidPtr(key); |
| 1428 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1429 | PyErr_Clear(); |
| 1430 | Py_XDECREF(v); |
| 1431 | } |
| 1432 | |
| 1433 | #define ADD_KEY(val) inskey(d, #val, val) |
| 1434 | |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 1435 | PyMODINIT_FUNC init_winreg(void) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1436 | { |
| 1437 | PyObject *m, *d; |
Fred Drake | 270e19b | 2000-06-29 16:14:14 +0000 | [diff] [blame] | 1438 | m = Py_InitModule3("_winreg", winreg_methods, module_doc); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 1439 | if (m == NULL) |
| 1440 | return; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1441 | d = PyModule_GetDict(m); |
Martin v. Löwis | 95c95ce | 2007-07-22 14:41:55 +0000 | [diff] [blame] | 1442 | Py_Type(&PyHKEY_Type) = &PyType_Type; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1443 | PyHKEY_Type.tp_doc = PyHKEY_doc; |
| 1444 | Py_INCREF(&PyHKEY_Type); |
| 1445 | if (PyDict_SetItemString(d, "HKEYType", |
| 1446 | (PyObject *)&PyHKEY_Type) != 0) |
| 1447 | return; |
| 1448 | Py_INCREF(PyExc_WindowsError); |
| 1449 | if (PyDict_SetItemString(d, "error", |
| 1450 | PyExc_WindowsError) != 0) |
| 1451 | return; |
| 1452 | |
| 1453 | /* Add the relevant constants */ |
| 1454 | ADD_KEY(HKEY_CLASSES_ROOT); |
| 1455 | ADD_KEY(HKEY_CURRENT_USER); |
| 1456 | ADD_KEY(HKEY_LOCAL_MACHINE); |
| 1457 | ADD_KEY(HKEY_USERS); |
| 1458 | ADD_KEY(HKEY_PERFORMANCE_DATA); |
| 1459 | #ifdef HKEY_CURRENT_CONFIG |
| 1460 | ADD_KEY(HKEY_CURRENT_CONFIG); |
| 1461 | #endif |
| 1462 | #ifdef HKEY_DYN_DATA |
| 1463 | ADD_KEY(HKEY_DYN_DATA); |
| 1464 | #endif |
| 1465 | ADD_INT(KEY_QUERY_VALUE); |
| 1466 | ADD_INT(KEY_SET_VALUE); |
| 1467 | ADD_INT(KEY_CREATE_SUB_KEY); |
| 1468 | ADD_INT(KEY_ENUMERATE_SUB_KEYS); |
| 1469 | ADD_INT(KEY_NOTIFY); |
| 1470 | ADD_INT(KEY_CREATE_LINK); |
| 1471 | ADD_INT(KEY_READ); |
| 1472 | ADD_INT(KEY_WRITE); |
| 1473 | ADD_INT(KEY_EXECUTE); |
| 1474 | ADD_INT(KEY_ALL_ACCESS); |
| 1475 | ADD_INT(REG_OPTION_RESERVED); |
| 1476 | ADD_INT(REG_OPTION_NON_VOLATILE); |
| 1477 | ADD_INT(REG_OPTION_VOLATILE); |
| 1478 | ADD_INT(REG_OPTION_CREATE_LINK); |
| 1479 | ADD_INT(REG_OPTION_BACKUP_RESTORE); |
| 1480 | ADD_INT(REG_OPTION_OPEN_LINK); |
| 1481 | ADD_INT(REG_LEGAL_OPTION); |
| 1482 | ADD_INT(REG_CREATED_NEW_KEY); |
| 1483 | ADD_INT(REG_OPENED_EXISTING_KEY); |
| 1484 | ADD_INT(REG_WHOLE_HIVE_VOLATILE); |
| 1485 | ADD_INT(REG_REFRESH_HIVE); |
| 1486 | ADD_INT(REG_NO_LAZY_FLUSH); |
| 1487 | ADD_INT(REG_NOTIFY_CHANGE_NAME); |
| 1488 | ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES); |
| 1489 | ADD_INT(REG_NOTIFY_CHANGE_LAST_SET); |
| 1490 | ADD_INT(REG_NOTIFY_CHANGE_SECURITY); |
| 1491 | ADD_INT(REG_LEGAL_CHANGE_FILTER); |
| 1492 | ADD_INT(REG_NONE); |
| 1493 | ADD_INT(REG_SZ); |
| 1494 | ADD_INT(REG_EXPAND_SZ); |
| 1495 | ADD_INT(REG_BINARY); |
| 1496 | ADD_INT(REG_DWORD); |
| 1497 | ADD_INT(REG_DWORD_LITTLE_ENDIAN); |
| 1498 | ADD_INT(REG_DWORD_BIG_ENDIAN); |
| 1499 | ADD_INT(REG_LINK); |
| 1500 | ADD_INT(REG_MULTI_SZ); |
| 1501 | ADD_INT(REG_RESOURCE_LIST); |
| 1502 | ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR); |
| 1503 | ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); |
| 1504 | } |
| 1505 | |