Python:查看注册表以查找程序的安装位置

Python:查看注册表以查找程序的安装位置,python,registry,key,winreg,Python,Registry,Key,Winreg,我正在尝试使用windows注册表查找程序的安装位置。我已经找到了我需要的钥匙和价值。它们位于Software\Microsoft\Windows\CurrentVersion\Uninstall文件夹中。但是,当我运行以下脚本时,它找不到该文件 from _winreg import * aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE) aKey = OpenKey(aReg, r'SOFTWARE\Microsoft\Windows\Curr

我正在尝试使用windows注册表查找程序的安装位置。我已经找到了我需要的钥匙和价值。它们位于Software\Microsoft\Windows\CurrentVersion\Uninstall文件夹中。但是,当我运行以下脚本时,它找不到该文件

from _winreg import *

aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)

aKey = OpenKey(aReg, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 0, KEY_READ)

[Pathname,regtype]=(QueryValueEx(aKey,"InstallLocation"))

print Pathname

CloseKey(aKey)
CloseKey(aReg)
回溯:

Traceback (most recent call last):
File "C:\Users\m.armstrong\Desktop\regression\regpy.py", line 7, in <module [Pathname,regtype]=(QueryValueEx(aKey,"InstallLocation"))
WindowsError: [Error 2] The system cannot find the file specified
回溯(最近一次呼叫最后一次):

文件“C:\Users\m.armstrong\Desktop\regression\regpy.py”,第7行,在中,您需要
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
InstallLocation

您需要
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
下某个子项的
InstallLocation

如果您想要一个特定的子键,只需将其名称添加到该路径

如果需要所有这些,请使用函数。大概是这样的:

for i in itertools.count():
    try:
        subname = EnumKey(akey, i)
    except WindowsError:
        break
    subkey = OpenKey(akey, subname, 0, KEY_READ)
    pathname, regtype = QueryValueEx(subkey, "InstallLocation")
    print subname, pathname
    CloseKey(subkey)

如果我用aKey=OpenKey(aReg,r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Andor SDK\u is1',0,KEY\u READ)指定确切的程序,会怎么样。它将仅找到此程序的安装位置。我已经试过了,它会返回上面的回溯。@Marmstrong:你确定你的名字完全正确吗?您是否尝试过使用
EnumKey
查看所有存在的键,查看它是否显示?