Index: _winreg.c =================================================================== --- _winreg.c (revision 55546) +++ _winreg.c (working copy) @@ -286,6 +286,17 @@ "2048 bytes) should be stored as files with the filenames stored in \n" "the configuration registry. This helps the registry perform efficiently."); +PyDoc_STRVAR(PyDisableReflectionKey_doc, +"Disables registry reflection for 32bit processes running on a 64bit\n" +"Operating System. Will generally raise NotImplemented if executed on\n" +"a 32bit Operating System.\n" +"If the key is not on the reflection list, the function succeeds but has no effect.\n" +"Disabling reflection for a key does not affect reflection of any subkeys."); + +PyDoc_STRVAR(PyEnableReflectionKey_doc, +"Restores registry reflection for the specified disabled key.\n" +"Restoring reflection for a key does not affect reflection of any subkeys."); + /* PyHKEY docstrings */ PyDoc_STRVAR(PyHKEY_doc, "PyHKEY Object - A Python object, representing a win32 registry key.\n" @@ -1405,12 +1416,86 @@ return Py_None; } +static PyObject * +PyDisableReflectionKey(PyObject *self, PyObject *args) +{ + HKEY hKey; + PyObject *obKey; + HMODULE hMod; + typedef LONG (WINAPI *RDRKFunc)(HKEY); + RDRKFunc pfn = NULL; + LONG rc; + + if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey)) + return NULL; + if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) + return NULL; + + // Only available on 64bit platforms, so we must load it + // dynamically. + hMod = GetModuleHandle("advapi32.dll"); + if (hMod) + pfn = (RDRKFunc)GetProcAddress(hMod, + "RegDisableReflectionKey"); + if (!pfn) { + PyErr_SetString(PyExc_NotImplementedError, + "not implemented on this platform"); + return NULL; + } + Py_BEGIN_ALLOW_THREADS + rc = (*pfn)(hKey); + Py_END_ALLOW_THREADS + if (rc != ERROR_SUCCESS) + return PyErr_SetFromWindowsErrWithFunction(rc, + "RegDisableReflectionKey"); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +PyEnableReflectionKey(PyObject *self, PyObject *args) +{ + HKEY hKey; + PyObject *obKey; + HMODULE hMod; + typedef LONG (WINAPI *RERKFunc)(HKEY); + RERKFunc pfn = NULL; + LONG rc; + + if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey)) + return NULL; + if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) + return NULL; + + // Only available on 64bit platforms, so we must load it + // dynamically. + hMod = GetModuleHandle("advapi32.dll"); + if (hMod) + pfn = (RERKFunc)GetProcAddress(hMod, + "RegEnableReflectionKey"); + if (!pfn) { + PyErr_SetString(PyExc_NotImplementedError, + "not implemented on this platform"); + return NULL; + } + Py_BEGIN_ALLOW_THREADS + rc = (*pfn)(hKey); + Py_END_ALLOW_THREADS + if (rc != ERROR_SUCCESS) + return PyErr_SetFromWindowsErrWithFunction(rc, + "RegEnableReflectionKey"); + Py_INCREF(Py_None); + return Py_None; +} + static struct PyMethodDef winreg_methods[] = { {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, + {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, PyDisableReflectionKey_doc}, + {"EnableReflectionKey", PyEnableReflectionKey, METH_VARARGS, PyEnableReflectionKey_doc}, {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc},