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