Python _winreg密钥路径不正确

use*_*650 8 python registry winreg

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

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

并输出:

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

但是这个值不是我用过的钥匙的一部分?这个值不在这个键上,我应该得到一个不同的值.我在RegEdit及其位于的位置搜索了值的位置

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
Run Code Online (Sandbox Code Playgroud)

当我使用命令提示符

REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Run Code Online (Sandbox Code Playgroud)

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

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"
Run Code Online (Sandbox Code Playgroud)

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

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

和输出

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

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

Ale*_*der 2

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

您应该禁用注册表反射

_winreg.DisableReflectionKey()
# Do stuff ...
# ...
# ...
_winreg.EnableReflectionKey()
Run Code Online (Sandbox Code Playgroud)