Python _winreg密钥路径不正确

时间:2015-05-17 13:27:44

标签: python registry winreg

当我尝试从此键读取值时,不返回此键的正确值,而是获得不同的键路径值?

import _winreg as wreg
key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
print(wreg.EnumValue(key, 0))

输出:

('SunJavaUpdateSched', u'"C:\\Program Files (x86)\\Common Files\\Java\\Java Update\\jusched.exe"', 1)

但是这个值不是我使用的键的一部分?这个值不在这个键上,我应该得到一个不同的值。 我搜索了RegEdit上值不正确的位置,它位于

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run

当我使用命令提示符

REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

我得到了正确的输出......

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
IgfxTray    REG_SZ    "C:\Windows\system32\igfxtray.exe"
HotKeysCmds    REG_SZ    "C:\Windows\system32\hkcmd.exe"
Persistence    REG_SZ    "C:\Windows\system32\igfxpers.exe"

然后我会尝试在python上使用os.popen ...

import os
buff = os.popen("REG QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
print(buff.read())

输出

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
SunJavaUpdateSched    REG_SZ    "C:\Program Files (x86)\Common Files\Java\Java Update\jusched.exe"

为什么这些不同?如何使用_winreg获取正确的值?

1 个答案:

答案 0 :(得分:2)

  

在WOW64上,32位应用程序查看与64位应用程序查看的注册表树分开的注册表树。注册表反射在两个视图之间复制特定的注册表项和值。

您应该停用注册表reflection

_winreg.DisableReflectionKey()
# Do stuff ...
# ...
# ...
_winreg.EnableReflectionKey()