2010-03-08 13 views
1

我的程序试图创建的如何关闭Python上的注册表重定向?

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

的关键,而是关键是在

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

创建并不能正常工作,为什么?我该如何解决它?

+0

什么不能正常工作?它如何失败?你能发布你的代码的相关部分吗? – 2010-03-08 21:07:21

回答

2

关于winreg中反射键功能的文档很少(并且缺少部分代码片段)。你真的需要this patch,但是直到它被应用并且这些修补程序创建了一个新的微型Python发行版,至少你可以根据patch添加的文档(这里是它们的RST)尝试DisableReflectionKey等路由:

+.. 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. 
+1

完全没有成功=/...尝试_winreg.DisableReflectionKey(_winreg.HKEY_LOCAL_MACHINE),或与一些常量的打开的键,但注意到发生 – Shady 2010-03-09 03:11:28

0

您可以使用:

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

在Python 2.6和上方。然而这只适用。

+0

我需要什么样的论据?这是要求一个 – Shady 2010-03-09 01:25:26

+0

禁用需要一个键或预定义的常量之一。 – 2016-02-01 12:38:06