如何关闭Python上的注册表重定向?

2024-09-26 22:10:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的程序试图在

HKLM\Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\

但是密钥是在

^{pr2}$

不能正常工作。。。为什么?我该怎么解决呢?在


Tags: test程序密钥softwaretoolsmicrosoftsharedpr2
2条回答

您可以使用:

import _winreg
_winreg.DisableReflectionKey(_winreg.HKEY_LOCAL_MACHINE)
# do stuff here
_winreg.EnableReflectionKey(_winreg.HKEY_LOCAL_MACHINE)

但是,这只适用于python2.6及更高版本。在

winreg中关于反射的关键特性的文档很少(而且缺少一些零碎的内容)。您确实需要this patch,但在应用它并使用这些修复程序制作新的Python微版本之前,至少可以根据补丁添加的文档尝试DisableReflectionKeyetc路径(以下是第一个):

+.. function:: DisableReflectionKey(key)
+   
+   Disables registry reflection for 32-bit processes running on a 64-bit
+   Operating System.
+   
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+   
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.

+   If the key is not on the reflection list, the function succeeds but has no
+   effect. Disabling reflection for a key does not affect reflection of any
+   subkeys.

+
+.. function:: EnableReflectionKey(key)
+
+   Restores registry reflection for the specified disabled key.
+   
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.
+   
+   Restoring reflection for a key does not affect reflection of any subkeys.
+
+
+.. function:: QueryReflectionKey(key)
+
+   Determines the reflection state for the specified key.
+   
+   *key* is an already open key, or one of the predefined :const:`HKEY_\*`
+   constants.
+   
+   Returns ``True`` if reflection is disabled.
+
+   Will generally raise :exc:`NotImplemented` if executed on a 32-bit
+   Operating System.

相关问题 更多 >

    热门问题