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