2010-03-08 14 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