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 | |
Neal Norwitz | 8dfc4a9 | 2007-08-11 06:39:53 +0000 | [diff] [blame] | 476 | static PyMemberDef PyHKEY_memberlist[] = { |
| 477 | {"handle", T_INT, OFF(hkey), READONLY}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 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); |
Neal Norwitz | 8dfc4a9 | 2007-08-11 06:39:53 +0000 | [diff] [blame] | 526 | PyErr_Format(PyExc_AttributeError, |
| 527 | "'%.50s' object has no attribute '%.400s'", |
| 528 | Py_Type(self)->tp_name, name); |
| 529 | return NULL; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /************************************************************************ |
| 533 | The public PyHKEY API (well, not public yet :-) |
| 534 | ************************************************************************/ |
| 535 | PyObject * |
| 536 | PyHKEY_New(HKEY hInit) |
| 537 | { |
| 538 | PyHKEYObject *key = PyObject_NEW(PyHKEYObject, &PyHKEY_Type); |
| 539 | if (key) |
| 540 | key->hkey = hInit; |
| 541 | return (PyObject *)key; |
| 542 | } |
| 543 | |
| 544 | BOOL |
| 545 | PyHKEY_Close(PyObject *ob_handle) |
| 546 | { |
| 547 | LONG rc; |
| 548 | PyHKEYObject *key; |
| 549 | |
| 550 | if (!PyHKEY_Check(ob_handle)) { |
| 551 | PyErr_SetString(PyExc_TypeError, "bad operand type"); |
| 552 | return FALSE; |
| 553 | } |
| 554 | key = (PyHKEYObject *)ob_handle; |
| 555 | rc = key->hkey ? RegCloseKey((HKEY)key->hkey) : ERROR_SUCCESS; |
| 556 | key->hkey = 0; |
| 557 | if (rc != ERROR_SUCCESS) |
| 558 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 559 | return rc == ERROR_SUCCESS; |
| 560 | } |
| 561 | |
| 562 | BOOL |
| 563 | PyHKEY_AsHKEY(PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK) |
| 564 | { |
| 565 | if (ob == Py_None) { |
| 566 | if (!bNoneOK) { |
| 567 | PyErr_SetString( |
| 568 | PyExc_TypeError, |
| 569 | "None is not a valid HKEY in this context"); |
| 570 | return FALSE; |
| 571 | } |
| 572 | *pHANDLE = (HKEY)0; |
| 573 | } |
| 574 | else if (PyHKEY_Check(ob)) { |
| 575 | PyHKEYObject *pH = (PyHKEYObject *)ob; |
| 576 | *pHANDLE = pH->hkey; |
| 577 | } |
Neal Norwitz | 1fe5f38 | 2007-08-31 04:32:55 +0000 | [diff] [blame^] | 578 | else if (PyLong_Check(ob)) { |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 579 | /* We also support integers */ |
| 580 | PyErr_Clear(); |
| 581 | *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob); |
| 582 | if (PyErr_Occurred()) |
| 583 | return FALSE; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 584 | } |
| 585 | else { |
| 586 | PyErr_SetString( |
| 587 | PyExc_TypeError, |
| 588 | "The object is not a PyHKEY object"); |
| 589 | return FALSE; |
| 590 | } |
| 591 | return TRUE; |
| 592 | } |
| 593 | |
| 594 | PyObject * |
| 595 | PyHKEY_FromHKEY(HKEY h) |
| 596 | { |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 597 | PyHKEYObject *op; |
| 598 | |
Guido van Rossum | e3a8e7e | 2002-08-19 19:26:42 +0000 | [diff] [blame] | 599 | /* Inline PyObject_New */ |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 600 | op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 601 | if (op == NULL) |
| 602 | return PyErr_NoMemory(); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 603 | PyObject_INIT(op, &PyHKEY_Type); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 604 | op->hkey = h; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 605 | return (PyObject *)op; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | /************************************************************************ |
| 610 | The module methods |
| 611 | ************************************************************************/ |
| 612 | BOOL |
| 613 | PyWinObject_CloseHKEY(PyObject *obHandle) |
| 614 | { |
| 615 | BOOL ok; |
| 616 | if (PyHKEY_Check(obHandle)) { |
| 617 | ok = PyHKEY_Close(obHandle); |
| 618 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 619 | #if SIZEOF_LONG >= SIZEOF_HKEY |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 620 | else if (PyInt_Check(obHandle)) { |
| 621 | long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle)); |
| 622 | ok = (rc == ERROR_SUCCESS); |
| 623 | if (!ok) |
| 624 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 625 | } |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 626 | #else |
| 627 | else if (PyLong_Check(obHandle)) { |
| 628 | long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle)); |
| 629 | ok = (rc == ERROR_SUCCESS); |
| 630 | if (!ok) |
| 631 | PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); |
| 632 | } |
| 633 | #endif |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 634 | else { |
| 635 | PyErr_SetString( |
| 636 | PyExc_TypeError, |
| 637 | "A handle must be a HKEY object or an integer"); |
| 638 | return FALSE; |
| 639 | } |
| 640 | return ok; |
| 641 | } |
| 642 | |
| 643 | |
| 644 | /* |
| 645 | Private Helper functions for the registry interfaces |
| 646 | |
| 647 | ** Note that fixupMultiSZ and countString have both had changes |
| 648 | ** made to support "incorrect strings". The registry specification |
| 649 | ** calls for strings to be terminated with 2 null bytes. It seems |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 650 | ** some commercial packages install strings which dont conform, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 651 | ** causing this code to fail - however, "regedit" etc still work |
| 652 | ** with these strings (ie only we dont!). |
| 653 | */ |
| 654 | static void |
| 655 | fixupMultiSZ(char **str, char *data, int len) |
| 656 | { |
| 657 | char *P; |
| 658 | int i; |
| 659 | char *Q; |
| 660 | |
| 661 | Q = data + len; |
| 662 | for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) { |
| 663 | str[i] = P; |
| 664 | for(; *P != '\0'; P++) |
| 665 | ; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | static int |
| 670 | countStrings(char *data, int len) |
| 671 | { |
| 672 | int strings; |
| 673 | char *P; |
| 674 | char *Q = data + len; |
| 675 | |
| 676 | for (P = data, strings = 0; P < Q && *P != '\0'; P++, strings++) |
| 677 | for (; P < Q && *P != '\0'; P++) |
| 678 | ; |
| 679 | return strings; |
| 680 | } |
| 681 | |
| 682 | /* Convert PyObject into Registry data. |
| 683 | Allocates space as needed. */ |
| 684 | static BOOL |
| 685 | Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) |
| 686 | { |
| 687 | int i,j; |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 688 | DWORD d; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 689 | switch (typ) { |
| 690 | case REG_DWORD: |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 691 | if (value != Py_None && !PyLong_Check(value)) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 692 | return FALSE; |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 693 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 694 | if (*retDataBuf==NULL){ |
| 695 | PyErr_NoMemory(); |
| 696 | return FALSE; |
| 697 | } |
| 698 | *retDataSize = sizeof(DWORD); |
| 699 | if (value == Py_None) { |
| 700 | DWORD zero = 0; |
| 701 | memcpy(*retDataBuf, &zero, sizeof(DWORD)); |
| 702 | } |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 703 | else { |
| 704 | d = PyLong_AsLong(value); |
| 705 | memcpy(*retDataBuf, &d, sizeof(DWORD)); |
| 706 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 707 | break; |
| 708 | case REG_SZ: |
| 709 | case REG_EXPAND_SZ: |
| 710 | { |
| 711 | int need_decref = 0; |
| 712 | if (value == Py_None) |
| 713 | *retDataSize = 1; |
| 714 | else { |
| 715 | if (PyUnicode_Check(value)) { |
| 716 | value = PyUnicode_AsEncodedString( |
| 717 | value, |
| 718 | "mbcs", |
| 719 | NULL); |
| 720 | if (value==NULL) |
| 721 | return FALSE; |
| 722 | need_decref = 1; |
| 723 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 724 | if (!PyBytes_Check(value)) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 725 | return FALSE; |
| 726 | *retDataSize = 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 727 | PyBytes_AS_STRING(value)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 728 | } |
| 729 | *retDataBuf = (BYTE *)PyMem_NEW(DWORD, *retDataSize); |
| 730 | if (*retDataBuf==NULL){ |
| 731 | PyErr_NoMemory(); |
| 732 | return FALSE; |
| 733 | } |
| 734 | if (value == Py_None) |
| 735 | strcpy((char *)*retDataBuf, ""); |
| 736 | else |
| 737 | strcpy((char *)*retDataBuf, |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 738 | PyBytes_AS_STRING(value)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 739 | if (need_decref) |
| 740 | Py_DECREF(value); |
| 741 | break; |
| 742 | } |
| 743 | case REG_MULTI_SZ: |
| 744 | { |
| 745 | DWORD size = 0; |
| 746 | char *P; |
| 747 | PyObject **obs = NULL; |
| 748 | |
| 749 | if (value == Py_None) |
| 750 | i = 0; |
| 751 | else { |
| 752 | if (!PyList_Check(value)) |
| 753 | return FALSE; |
| 754 | i = PyList_Size(value); |
| 755 | } |
| 756 | obs = malloc(sizeof(PyObject *) * i); |
| 757 | memset(obs, 0, sizeof(PyObject *) * i); |
| 758 | for (j = 0; j < i; j++) |
| 759 | { |
| 760 | PyObject *t; |
| 761 | t = PyList_GET_ITEM( |
| 762 | (PyListObject *)value,j); |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 763 | if (PyBytes_Check(t)) { |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 764 | obs[j] = t; |
| 765 | Py_INCREF(t); |
| 766 | } else if (PyUnicode_Check(t)) { |
| 767 | obs[j] = PyUnicode_AsEncodedString( |
| 768 | t, |
| 769 | "mbcs", |
| 770 | NULL); |
| 771 | if (obs[j]==NULL) |
| 772 | goto reg_multi_fail; |
| 773 | } else |
| 774 | goto reg_multi_fail; |
| 775 | size += 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 776 | PyBytes_AS_STRING(obs[j])); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | *retDataSize = size + 1; |
| 780 | *retDataBuf = (BYTE *)PyMem_NEW(char, |
| 781 | *retDataSize); |
| 782 | if (*retDataBuf==NULL){ |
| 783 | PyErr_NoMemory(); |
| 784 | goto reg_multi_fail; |
| 785 | } |
| 786 | P = (char *)*retDataBuf; |
| 787 | |
| 788 | for (j = 0; j < i; j++) |
| 789 | { |
| 790 | PyObject *t; |
| 791 | t = obs[j]; |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 792 | strcpy(P, PyBytes_AS_STRING(t)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 793 | P += 1 + strlen( |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 794 | PyBytes_AS_STRING(t)); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 795 | Py_DECREF(obs[j]); |
| 796 | } |
| 797 | /* And doubly-terminate the list... */ |
| 798 | *P = '\0'; |
| 799 | free(obs); |
| 800 | break; |
| 801 | reg_multi_fail: |
| 802 | if (obs) { |
| 803 | for (j = 0; j < i; j++) |
| 804 | Py_XDECREF(obs[j]); |
| 805 | |
| 806 | free(obs); |
| 807 | } |
| 808 | return FALSE; |
| 809 | } |
| 810 | case REG_BINARY: |
| 811 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 812 | support it natively, we should handle the bits. */ |
| 813 | default: |
| 814 | if (value == Py_None) |
| 815 | *retDataSize = 0; |
| 816 | else { |
Neal Norwitz | 1385b89 | 2007-08-26 23:07:13 +0000 | [diff] [blame] | 817 | PyBuffer view; |
| 818 | |
| 819 | if (!PyObject_CheckBuffer(value)) { |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 820 | PyErr_Format(PyExc_TypeError, |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 821 | "Objects of type '%s' can not " |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 822 | "be used as binary registry values", |
Mark Hammond | 4e80bb5 | 2000-07-28 03:44:41 +0000 | [diff] [blame] | 823 | value->ob_type->tp_name); |
| 824 | return FALSE; |
| 825 | } |
Neal Norwitz | 1385b89 | 2007-08-26 23:07:13 +0000 | [diff] [blame] | 826 | |
| 827 | if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0) |
| 828 | return FALSE; |
| 829 | |
| 830 | *retDataBuf = (BYTE *)PyMem_NEW(char, view.len); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 831 | if (*retDataBuf==NULL){ |
Neal Norwitz | 1385b89 | 2007-08-26 23:07:13 +0000 | [diff] [blame] | 832 | PyObject_ReleaseBuffer(value, &view); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 833 | PyErr_NoMemory(); |
| 834 | return FALSE; |
| 835 | } |
Neal Norwitz | 1385b89 | 2007-08-26 23:07:13 +0000 | [diff] [blame] | 836 | *retDataSize = view.len; |
| 837 | memcpy(*retDataBuf, view.buf, view.len); |
| 838 | PyObject_ReleaseBuffer(value, &view); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 839 | } |
| 840 | break; |
| 841 | } |
| 842 | return TRUE; |
| 843 | } |
| 844 | |
| 845 | /* Convert Registry data into PyObject*/ |
| 846 | static PyObject * |
| 847 | Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ) |
| 848 | { |
| 849 | PyObject *obData; |
| 850 | |
| 851 | switch (typ) { |
| 852 | case REG_DWORD: |
| 853 | if (retDataSize == 0) |
| 854 | obData = Py_BuildValue("i", 0); |
| 855 | else |
| 856 | obData = Py_BuildValue("i", |
| 857 | *(int *)retDataBuf); |
| 858 | break; |
| 859 | case REG_SZ: |
| 860 | case REG_EXPAND_SZ: |
| 861 | /* retDataBuf may or may not have a trailing NULL in |
| 862 | the buffer. */ |
| 863 | if (retDataSize && retDataBuf[retDataSize-1] == '\0') |
| 864 | --retDataSize; |
| 865 | if (retDataSize ==0) |
| 866 | retDataBuf = ""; |
| 867 | obData = PyUnicode_DecodeMBCS(retDataBuf, |
| 868 | retDataSize, |
| 869 | NULL); |
| 870 | break; |
| 871 | case REG_MULTI_SZ: |
| 872 | if (retDataSize == 0) |
| 873 | obData = PyList_New(0); |
| 874 | else |
| 875 | { |
| 876 | int index = 0; |
| 877 | int s = countStrings(retDataBuf, retDataSize); |
| 878 | char **str = (char **)malloc(sizeof(char *)*s); |
| 879 | if (str == NULL) |
| 880 | return PyErr_NoMemory(); |
| 881 | |
| 882 | fixupMultiSZ(str, retDataBuf, retDataSize); |
| 883 | obData = PyList_New(s); |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 884 | if (obData == NULL) |
| 885 | return NULL; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 886 | for (index = 0; index < s; index++) |
| 887 | { |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 888 | size_t len = _mbstrlen(str[index]); |
| 889 | if (len > INT_MAX) { |
| 890 | PyErr_SetString(PyExc_OverflowError, |
| 891 | "registry string is too long for a Python string"); |
| 892 | Py_DECREF(obData); |
| 893 | return NULL; |
| 894 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 895 | PyList_SetItem(obData, |
| 896 | index, |
| 897 | PyUnicode_DecodeMBCS( |
| 898 | (const char *)str[index], |
Fred Drake | 25e1726 | 2000-06-30 17:48:51 +0000 | [diff] [blame] | 899 | (int)len, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 900 | NULL) |
| 901 | ); |
| 902 | } |
| 903 | free(str); |
| 904 | |
| 905 | break; |
| 906 | } |
| 907 | case REG_BINARY: |
| 908 | /* ALSO handle ALL unknown data types here. Even if we can't |
| 909 | support it natively, we should handle the bits. */ |
| 910 | default: |
| 911 | if (retDataSize == 0) { |
| 912 | Py_INCREF(Py_None); |
| 913 | obData = Py_None; |
| 914 | } |
| 915 | else |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 916 | obData = Py_BuildValue("y#", |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 917 | (char *)retDataBuf, |
| 918 | retDataSize); |
| 919 | break; |
| 920 | } |
| 921 | if (obData == NULL) |
| 922 | return NULL; |
| 923 | else |
| 924 | return obData; |
| 925 | } |
| 926 | |
| 927 | /* The Python methods */ |
| 928 | |
| 929 | static PyObject * |
| 930 | PyCloseKey(PyObject *self, PyObject *args) |
| 931 | { |
| 932 | PyObject *obKey; |
| 933 | if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey)) |
| 934 | return NULL; |
| 935 | if (!PyHKEY_Close(obKey)) |
| 936 | return NULL; |
| 937 | Py_INCREF(Py_None); |
| 938 | return Py_None; |
| 939 | } |
| 940 | |
| 941 | static PyObject * |
| 942 | PyConnectRegistry(PyObject *self, PyObject *args) |
| 943 | { |
| 944 | HKEY hKey; |
| 945 | PyObject *obKey; |
| 946 | char *szCompName = NULL; |
| 947 | HKEY retKey; |
| 948 | long rc; |
| 949 | if (!PyArg_ParseTuple(args, "zO:ConnectRegistry", &szCompName, &obKey)) |
| 950 | return NULL; |
| 951 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 952 | return NULL; |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 953 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 954 | rc = RegConnectRegistry(szCompName, hKey, &retKey); |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 955 | Py_END_ALLOW_THREADS |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 956 | if (rc != ERROR_SUCCESS) |
| 957 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 958 | "ConnectRegistry"); |
| 959 | return PyHKEY_FromHKEY(retKey); |
| 960 | } |
| 961 | |
| 962 | static PyObject * |
| 963 | PyCreateKey(PyObject *self, PyObject *args) |
| 964 | { |
| 965 | HKEY hKey; |
| 966 | PyObject *obKey; |
| 967 | char *subKey; |
| 968 | HKEY retKey; |
| 969 | long rc; |
| 970 | if (!PyArg_ParseTuple(args, "Oz:CreateKey", &obKey, &subKey)) |
| 971 | return NULL; |
| 972 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 973 | return NULL; |
| 974 | rc = RegCreateKey(hKey, subKey, &retKey); |
| 975 | if (rc != ERROR_SUCCESS) |
| 976 | return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); |
| 977 | return PyHKEY_FromHKEY(retKey); |
| 978 | } |
| 979 | |
| 980 | static PyObject * |
| 981 | PyDeleteKey(PyObject *self, PyObject *args) |
| 982 | { |
| 983 | HKEY hKey; |
| 984 | PyObject *obKey; |
| 985 | char *subKey; |
| 986 | long rc; |
| 987 | if (!PyArg_ParseTuple(args, "Os:DeleteKey", &obKey, &subKey)) |
| 988 | return NULL; |
| 989 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 990 | return NULL; |
| 991 | rc = RegDeleteKey(hKey, subKey ); |
| 992 | if (rc != ERROR_SUCCESS) |
| 993 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); |
| 994 | Py_INCREF(Py_None); |
| 995 | return Py_None; |
| 996 | } |
| 997 | |
| 998 | static PyObject * |
| 999 | PyDeleteValue(PyObject *self, PyObject *args) |
| 1000 | { |
| 1001 | HKEY hKey; |
| 1002 | PyObject *obKey; |
| 1003 | char *subKey; |
| 1004 | long rc; |
| 1005 | if (!PyArg_ParseTuple(args, "Oz:DeleteValue", &obKey, &subKey)) |
| 1006 | return NULL; |
| 1007 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1008 | return NULL; |
| 1009 | Py_BEGIN_ALLOW_THREADS |
| 1010 | rc = RegDeleteValue(hKey, subKey); |
| 1011 | Py_END_ALLOW_THREADS |
| 1012 | if (rc !=ERROR_SUCCESS) |
| 1013 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1014 | "RegDeleteValue"); |
| 1015 | Py_INCREF(Py_None); |
| 1016 | return Py_None; |
| 1017 | } |
| 1018 | |
| 1019 | static PyObject * |
| 1020 | PyEnumKey(PyObject *self, PyObject *args) |
| 1021 | { |
| 1022 | HKEY hKey; |
| 1023 | PyObject *obKey; |
| 1024 | int index; |
| 1025 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1026 | PyObject *retStr; |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1027 | char tmpbuf[256]; /* max key name length is 255 */ |
Georg Brandl | b2699b2 | 2006-02-18 23:44:24 +0000 | [diff] [blame] | 1028 | DWORD len = sizeof(tmpbuf); /* includes NULL terminator */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1029 | |
| 1030 | if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) |
| 1031 | return NULL; |
| 1032 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1033 | return NULL; |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1034 | |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1035 | Py_BEGIN_ALLOW_THREADS |
| 1036 | rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL); |
| 1037 | Py_END_ALLOW_THREADS |
| 1038 | if (rc != ERROR_SUCCESS) |
| 1039 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx"); |
Tim Peters | 313fcd4 | 2006-02-19 04:05:39 +0000 | [diff] [blame] | 1040 | |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1041 | retStr = PyUnicode_FromStringAndSize(tmpbuf, len); |
Georg Brandl | 9a928e7 | 2006-02-18 23:35:11 +0000 | [diff] [blame] | 1042 | return retStr; /* can be NULL */ |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static PyObject * |
| 1046 | PyEnumValue(PyObject *self, PyObject *args) |
| 1047 | { |
| 1048 | HKEY hKey; |
| 1049 | PyObject *obKey; |
| 1050 | int index; |
| 1051 | long rc; |
| 1052 | char *retValueBuf; |
| 1053 | char *retDataBuf; |
| 1054 | DWORD retValueSize; |
| 1055 | DWORD retDataSize; |
| 1056 | DWORD typ; |
| 1057 | PyObject *obData; |
| 1058 | PyObject *retVal; |
| 1059 | |
| 1060 | if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) |
| 1061 | return NULL; |
| 1062 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1063 | return NULL; |
| 1064 | |
| 1065 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, |
| 1066 | NULL, |
| 1067 | &retValueSize, &retDataSize, NULL, NULL)) |
| 1068 | != ERROR_SUCCESS) |
| 1069 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1070 | "RegQueryInfoKey"); |
| 1071 | ++retValueSize; /* include null terminators */ |
| 1072 | ++retDataSize; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1073 | retValueBuf = (char *)PyMem_Malloc(retValueSize); |
| 1074 | if (retValueBuf == NULL) |
| 1075 | return PyErr_NoMemory(); |
| 1076 | retDataBuf = (char *)PyMem_Malloc(retDataSize); |
| 1077 | if (retDataBuf == NULL) { |
| 1078 | PyMem_Free(retValueBuf); |
| 1079 | return PyErr_NoMemory(); |
| 1080 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1081 | |
| 1082 | Py_BEGIN_ALLOW_THREADS |
| 1083 | rc = RegEnumValue(hKey, |
| 1084 | index, |
| 1085 | retValueBuf, |
| 1086 | &retValueSize, |
| 1087 | NULL, |
| 1088 | &typ, |
| 1089 | (BYTE *)retDataBuf, |
| 1090 | &retDataSize); |
| 1091 | Py_END_ALLOW_THREADS |
| 1092 | |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1093 | if (rc != ERROR_SUCCESS) { |
| 1094 | retVal = PyErr_SetFromWindowsErrWithFunction(rc, |
| 1095 | "PyRegEnumValue"); |
| 1096 | goto fail; |
| 1097 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1098 | obData = Reg2Py(retDataBuf, retDataSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1099 | if (obData == NULL) { |
| 1100 | retVal = NULL; |
| 1101 | goto fail; |
| 1102 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1103 | retVal = Py_BuildValue("UOi", retValueBuf, obData, typ); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1104 | Py_DECREF(obData); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1105 | fail: |
| 1106 | PyMem_Free(retValueBuf); |
| 1107 | PyMem_Free(retDataBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1108 | return retVal; |
| 1109 | } |
| 1110 | |
| 1111 | static PyObject * |
| 1112 | PyFlushKey(PyObject *self, PyObject *args) |
| 1113 | { |
| 1114 | HKEY hKey; |
| 1115 | PyObject *obKey; |
| 1116 | long rc; |
| 1117 | if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey)) |
| 1118 | return NULL; |
| 1119 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1120 | return NULL; |
| 1121 | Py_BEGIN_ALLOW_THREADS |
| 1122 | rc = RegFlushKey(hKey); |
| 1123 | Py_END_ALLOW_THREADS |
| 1124 | if (rc != ERROR_SUCCESS) |
| 1125 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); |
| 1126 | Py_INCREF(Py_None); |
| 1127 | return Py_None; |
| 1128 | } |
| 1129 | static PyObject * |
| 1130 | PyLoadKey(PyObject *self, PyObject *args) |
| 1131 | { |
| 1132 | HKEY hKey; |
| 1133 | PyObject *obKey; |
| 1134 | char *subKey; |
| 1135 | char *fileName; |
| 1136 | |
| 1137 | long rc; |
| 1138 | if (!PyArg_ParseTuple(args, "Oss:LoadKey", &obKey, &subKey, &fileName)) |
| 1139 | return NULL; |
| 1140 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1141 | return NULL; |
| 1142 | Py_BEGIN_ALLOW_THREADS |
| 1143 | rc = RegLoadKey(hKey, subKey, fileName ); |
| 1144 | Py_END_ALLOW_THREADS |
| 1145 | if (rc != ERROR_SUCCESS) |
| 1146 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); |
| 1147 | Py_INCREF(Py_None); |
| 1148 | return Py_None; |
| 1149 | } |
| 1150 | |
| 1151 | static PyObject * |
| 1152 | PyOpenKey(PyObject *self, PyObject *args) |
| 1153 | { |
| 1154 | HKEY hKey; |
| 1155 | PyObject *obKey; |
| 1156 | |
| 1157 | char *subKey; |
| 1158 | int res = 0; |
| 1159 | HKEY retKey; |
| 1160 | long rc; |
| 1161 | REGSAM sam = KEY_READ; |
| 1162 | if (!PyArg_ParseTuple(args, "Oz|ii:OpenKey", &obKey, &subKey, |
| 1163 | &res, &sam)) |
| 1164 | return NULL; |
| 1165 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1166 | return NULL; |
| 1167 | |
| 1168 | Py_BEGIN_ALLOW_THREADS |
| 1169 | rc = RegOpenKeyEx(hKey, subKey, res, sam, &retKey); |
| 1170 | Py_END_ALLOW_THREADS |
| 1171 | if (rc != ERROR_SUCCESS) |
| 1172 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); |
| 1173 | return PyHKEY_FromHKEY(retKey); |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | static PyObject * |
| 1178 | PyQueryInfoKey(PyObject *self, PyObject *args) |
| 1179 | { |
| 1180 | HKEY hKey; |
| 1181 | PyObject *obKey; |
| 1182 | long rc; |
| 1183 | DWORD nSubKeys, nValues; |
| 1184 | FILETIME ft; |
| 1185 | LARGE_INTEGER li; |
| 1186 | PyObject *l; |
| 1187 | PyObject *ret; |
| 1188 | if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey)) |
| 1189 | return NULL; |
| 1190 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1191 | return NULL; |
| 1192 | if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL, |
| 1193 | &nValues, NULL, NULL, NULL, &ft)) |
| 1194 | != ERROR_SUCCESS) |
| 1195 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey"); |
| 1196 | li.LowPart = ft.dwLowDateTime; |
| 1197 | li.HighPart = ft.dwHighDateTime; |
| 1198 | l = PyLong_FromLongLong(li.QuadPart); |
| 1199 | if (l == NULL) |
| 1200 | return NULL; |
| 1201 | ret = Py_BuildValue("iiO", nSubKeys, nValues, l); |
| 1202 | Py_DECREF(l); |
| 1203 | return ret; |
| 1204 | } |
| 1205 | |
| 1206 | static PyObject * |
| 1207 | PyQueryValue(PyObject *self, PyObject *args) |
| 1208 | { |
| 1209 | HKEY hKey; |
| 1210 | PyObject *obKey; |
| 1211 | char *subKey; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1212 | long rc; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1213 | PyObject *retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1214 | char *retBuf; |
| 1215 | long bufSize = 0; |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1216 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1217 | if (!PyArg_ParseTuple(args, "Oz:QueryValue", &obKey, &subKey)) |
| 1218 | return NULL; |
| 1219 | |
| 1220 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1221 | return NULL; |
| 1222 | if ((rc = RegQueryValue(hKey, subKey, NULL, &bufSize)) |
| 1223 | != ERROR_SUCCESS) |
| 1224 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1225 | "RegQueryValue"); |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1226 | retBuf = (char *)PyMem_Malloc(bufSize); |
| 1227 | if (retBuf == NULL) |
| 1228 | return PyErr_NoMemory(); |
| 1229 | |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1230 | if ((rc = RegQueryValue(hKey, subKey, retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1231 | != ERROR_SUCCESS) { |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1232 | PyMem_Free(retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1233 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1234 | "RegQueryValue"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1235 | } |
Guido van Rossum | a8c360e | 2007-07-17 20:50:43 +0000 | [diff] [blame] | 1236 | |
| 1237 | retStr = PyUnicode_DecodeMBCS(retBuf, strlen(retBuf), NULL); |
| 1238 | PyMem_Free(retBuf); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1239 | return retStr; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static PyObject * |
| 1243 | PyQueryValueEx(PyObject *self, PyObject *args) |
| 1244 | { |
| 1245 | HKEY hKey; |
| 1246 | PyObject *obKey; |
| 1247 | char *valueName; |
| 1248 | |
| 1249 | long rc; |
| 1250 | char *retBuf; |
| 1251 | DWORD bufSize = 0; |
| 1252 | DWORD typ; |
| 1253 | PyObject *obData; |
| 1254 | PyObject *result; |
| 1255 | |
| 1256 | if (!PyArg_ParseTuple(args, "Oz:QueryValueEx", &obKey, &valueName)) |
| 1257 | return NULL; |
| 1258 | |
| 1259 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1260 | return NULL; |
| 1261 | if ((rc = RegQueryValueEx(hKey, valueName, |
| 1262 | NULL, NULL, NULL, |
| 1263 | &bufSize)) |
| 1264 | != ERROR_SUCCESS) |
| 1265 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1266 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1267 | retBuf = (char *)PyMem_Malloc(bufSize); |
| 1268 | if (retBuf == NULL) |
| 1269 | return PyErr_NoMemory(); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1270 | if ((rc = RegQueryValueEx(hKey, valueName, NULL, |
| 1271 | &typ, (BYTE *)retBuf, &bufSize)) |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1272 | != ERROR_SUCCESS) { |
| 1273 | PyMem_Free(retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1274 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1275 | "RegQueryValueEx"); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1276 | } |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1277 | obData = Reg2Py(retBuf, bufSize, typ); |
Guido van Rossum | a6a38ad | 2003-11-30 22:01:43 +0000 | [diff] [blame] | 1278 | PyMem_Free((void *)retBuf); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1279 | if (obData == NULL) |
| 1280 | return NULL; |
| 1281 | result = Py_BuildValue("Oi", obData, typ); |
| 1282 | Py_DECREF(obData); |
| 1283 | return result; |
| 1284 | } |
| 1285 | |
| 1286 | |
| 1287 | static PyObject * |
| 1288 | PySaveKey(PyObject *self, PyObject *args) |
| 1289 | { |
| 1290 | HKEY hKey; |
| 1291 | PyObject *obKey; |
| 1292 | char *fileName; |
| 1293 | LPSECURITY_ATTRIBUTES pSA = NULL; |
| 1294 | |
| 1295 | long rc; |
| 1296 | if (!PyArg_ParseTuple(args, "Os:SaveKey", &obKey, &fileName)) |
| 1297 | return NULL; |
| 1298 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1299 | return NULL; |
| 1300 | /* One day we may get security into the core? |
| 1301 | if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE)) |
| 1302 | return NULL; |
| 1303 | */ |
| 1304 | Py_BEGIN_ALLOW_THREADS |
| 1305 | rc = RegSaveKey(hKey, fileName, pSA ); |
| 1306 | Py_END_ALLOW_THREADS |
| 1307 | if (rc != ERROR_SUCCESS) |
| 1308 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); |
| 1309 | Py_INCREF(Py_None); |
| 1310 | return Py_None; |
| 1311 | } |
| 1312 | |
| 1313 | static PyObject * |
| 1314 | PySetValue(PyObject *self, PyObject *args) |
| 1315 | { |
| 1316 | HKEY hKey; |
| 1317 | PyObject *obKey; |
| 1318 | char *subKey; |
| 1319 | char *str; |
| 1320 | DWORD typ; |
| 1321 | DWORD len; |
| 1322 | long rc; |
| 1323 | PyObject *obStrVal; |
| 1324 | PyObject *obSubKey; |
| 1325 | if (!PyArg_ParseTuple(args, "OOiO:SetValue", |
| 1326 | &obKey, |
| 1327 | &obSubKey, |
| 1328 | &typ, |
| 1329 | &obStrVal)) |
| 1330 | return NULL; |
| 1331 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1332 | return NULL; |
| 1333 | if (typ != REG_SZ) { |
| 1334 | PyErr_SetString(PyExc_TypeError, |
Thomas Heller | e1d18f5 | 2002-12-20 20:13:35 +0000 | [diff] [blame] | 1335 | "Type must be _winreg.REG_SZ"); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1336 | return NULL; |
| 1337 | } |
| 1338 | /* XXX - need Unicode support */ |
| 1339 | str = PyString_AsString(obStrVal); |
| 1340 | if (str == NULL) |
| 1341 | return NULL; |
| 1342 | len = PyString_Size(obStrVal); |
| 1343 | if (obSubKey == Py_None) |
| 1344 | subKey = NULL; |
| 1345 | else { |
| 1346 | subKey = PyString_AsString(obSubKey); |
| 1347 | if (subKey == NULL) |
| 1348 | return NULL; |
| 1349 | } |
| 1350 | Py_BEGIN_ALLOW_THREADS |
| 1351 | rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1); |
| 1352 | Py_END_ALLOW_THREADS |
| 1353 | if (rc != ERROR_SUCCESS) |
| 1354 | return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); |
| 1355 | Py_INCREF(Py_None); |
| 1356 | return Py_None; |
| 1357 | } |
| 1358 | |
| 1359 | static PyObject * |
| 1360 | PySetValueEx(PyObject *self, PyObject *args) |
| 1361 | { |
| 1362 | HKEY hKey; |
| 1363 | PyObject *obKey; |
| 1364 | char *valueName; |
| 1365 | PyObject *obRes; |
| 1366 | PyObject *value; |
| 1367 | BYTE *data; |
| 1368 | DWORD len; |
| 1369 | DWORD typ; |
| 1370 | |
| 1371 | LONG rc; |
| 1372 | |
| 1373 | if (!PyArg_ParseTuple(args, "OzOiO:SetValueEx", |
| 1374 | &obKey, |
| 1375 | &valueName, |
| 1376 | &obRes, |
| 1377 | &typ, |
| 1378 | &value)) |
| 1379 | return NULL; |
| 1380 | if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) |
| 1381 | return NULL; |
| 1382 | if (!Py2Reg(value, typ, &data, &len)) |
| 1383 | { |
| 1384 | if (!PyErr_Occurred()) |
| 1385 | PyErr_SetString(PyExc_ValueError, |
| 1386 | "Could not convert the data to the specified type."); |
| 1387 | return NULL; |
| 1388 | } |
| 1389 | Py_BEGIN_ALLOW_THREADS |
| 1390 | rc = RegSetValueEx(hKey, valueName, 0, typ, data, len); |
| 1391 | Py_END_ALLOW_THREADS |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 1392 | PyMem_DEL(data); |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1393 | if (rc != ERROR_SUCCESS) |
| 1394 | return PyErr_SetFromWindowsErrWithFunction(rc, |
| 1395 | "RegSetValueEx"); |
| 1396 | Py_INCREF(Py_None); |
| 1397 | return Py_None; |
| 1398 | } |
| 1399 | |
| 1400 | static struct PyMethodDef winreg_methods[] = { |
Neal Norwitz | 031829d | 2002-03-31 14:37:44 +0000 | [diff] [blame] | 1401 | {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, |
| 1402 | {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, |
| 1403 | {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, |
| 1404 | {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, |
| 1405 | {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, |
| 1406 | {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, |
| 1407 | {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, |
| 1408 | {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc}, |
| 1409 | {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc}, |
| 1410 | {"OpenKey", PyOpenKey, METH_VARARGS, OpenKey_doc}, |
| 1411 | {"OpenKeyEx", PyOpenKey, METH_VARARGS, OpenKeyEx_doc}, |
| 1412 | {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc}, |
| 1413 | {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc}, |
| 1414 | {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc}, |
| 1415 | {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc}, |
| 1416 | {"SetValue", PySetValue, METH_VARARGS, SetValue_doc}, |
| 1417 | {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc}, |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1418 | NULL, |
| 1419 | }; |
| 1420 | |
| 1421 | static void |
| 1422 | insint(PyObject * d, char * name, long value) |
| 1423 | { |
| 1424 | PyObject *v = PyInt_FromLong(value); |
| 1425 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1426 | PyErr_Clear(); |
| 1427 | Py_XDECREF(v); |
| 1428 | } |
| 1429 | |
| 1430 | #define ADD_INT(val) insint(d, #val, val) |
| 1431 | |
| 1432 | static void |
| 1433 | inskey(PyObject * d, char * name, HKEY key) |
| 1434 | { |
| 1435 | PyObject *v = PyLong_FromVoidPtr(key); |
| 1436 | if (!v || PyDict_SetItemString(d, name, v)) |
| 1437 | PyErr_Clear(); |
| 1438 | Py_XDECREF(v); |
| 1439 | } |
| 1440 | |
| 1441 | #define ADD_KEY(val) inskey(d, #val, val) |
| 1442 | |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 1443 | PyMODINIT_FUNC init_winreg(void) |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1444 | { |
| 1445 | PyObject *m, *d; |
Fred Drake | 270e19b | 2000-06-29 16:14:14 +0000 | [diff] [blame] | 1446 | m = Py_InitModule3("_winreg", winreg_methods, module_doc); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 1447 | if (m == NULL) |
| 1448 | return; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1449 | d = PyModule_GetDict(m); |
Martin v. Löwis | 95c95ce | 2007-07-22 14:41:55 +0000 | [diff] [blame] | 1450 | Py_Type(&PyHKEY_Type) = &PyType_Type; |
Guido van Rossum | 9f3712c | 2000-03-28 20:37:15 +0000 | [diff] [blame] | 1451 | PyHKEY_Type.tp_doc = PyHKEY_doc; |
| 1452 | Py_INCREF(&PyHKEY_Type); |
| 1453 | if (PyDict_SetItemString(d, "HKEYType", |
| 1454 | (PyObject *)&PyHKEY_Type) != 0) |
| 1455 | return; |
| 1456 | Py_INCREF(PyExc_WindowsError); |
| 1457 | if (PyDict_SetItemString(d, "error", |
| 1458 | PyExc_WindowsError) != 0) |
| 1459 | return; |
| 1460 | |
| 1461 | /* Add the relevant constants */ |
| 1462 | ADD_KEY(HKEY_CLASSES_ROOT); |
| 1463 | ADD_KEY(HKEY_CURRENT_USER); |
| 1464 | ADD_KEY(HKEY_LOCAL_MACHINE); |
| 1465 | ADD_KEY(HKEY_USERS); |
| 1466 | ADD_KEY(HKEY_PERFORMANCE_DATA); |
| 1467 | #ifdef HKEY_CURRENT_CONFIG |
| 1468 | ADD_KEY(HKEY_CURRENT_CONFIG); |
| 1469 | #endif |
| 1470 | #ifdef HKEY_DYN_DATA |
| 1471 | ADD_KEY(HKEY_DYN_DATA); |
| 1472 | #endif |
| 1473 | ADD_INT(KEY_QUERY_VALUE); |
| 1474 | ADD_INT(KEY_SET_VALUE); |
| 1475 | ADD_INT(KEY_CREATE_SUB_KEY); |
| 1476 | ADD_INT(KEY_ENUMERATE_SUB_KEYS); |
| 1477 | ADD_INT(KEY_NOTIFY); |
| 1478 | ADD_INT(KEY_CREATE_LINK); |
| 1479 | ADD_INT(KEY_READ); |
| 1480 | ADD_INT(KEY_WRITE); |
| 1481 | ADD_INT(KEY_EXECUTE); |
| 1482 | ADD_INT(KEY_ALL_ACCESS); |
| 1483 | ADD_INT(REG_OPTION_RESERVED); |
| 1484 | ADD_INT(REG_OPTION_NON_VOLATILE); |
| 1485 | ADD_INT(REG_OPTION_VOLATILE); |
| 1486 | ADD_INT(REG_OPTION_CREATE_LINK); |
| 1487 | ADD_INT(REG_OPTION_BACKUP_RESTORE); |
| 1488 | ADD_INT(REG_OPTION_OPEN_LINK); |
| 1489 | ADD_INT(REG_LEGAL_OPTION); |
| 1490 | ADD_INT(REG_CREATED_NEW_KEY); |
| 1491 | ADD_INT(REG_OPENED_EXISTING_KEY); |
| 1492 | ADD_INT(REG_WHOLE_HIVE_VOLATILE); |
| 1493 | ADD_INT(REG_REFRESH_HIVE); |
| 1494 | ADD_INT(REG_NO_LAZY_FLUSH); |
| 1495 | ADD_INT(REG_NOTIFY_CHANGE_NAME); |
| 1496 | ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES); |
| 1497 | ADD_INT(REG_NOTIFY_CHANGE_LAST_SET); |
| 1498 | ADD_INT(REG_NOTIFY_CHANGE_SECURITY); |
| 1499 | ADD_INT(REG_LEGAL_CHANGE_FILTER); |
| 1500 | ADD_INT(REG_NONE); |
| 1501 | ADD_INT(REG_SZ); |
| 1502 | ADD_INT(REG_EXPAND_SZ); |
| 1503 | ADD_INT(REG_BINARY); |
| 1504 | ADD_INT(REG_DWORD); |
| 1505 | ADD_INT(REG_DWORD_LITTLE_ENDIAN); |
| 1506 | ADD_INT(REG_DWORD_BIG_ENDIAN); |
| 1507 | ADD_INT(REG_LINK); |
| 1508 | ADD_INT(REG_MULTI_SZ); |
| 1509 | ADD_INT(REG_RESOURCE_LIST); |
| 1510 | ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR); |
| 1511 | ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); |
| 1512 | } |
| 1513 | |