Python:查看注册表以查找程序的安装位置 [英] Python: Look into the registry to find install location of a program
问题描述
我正在尝试使用 Windows 注册表查找程序的安装位置.我设法找到了我需要的关键和价值.它们位于 Software\Microsoft\Windows\CurrentVersion\Uninstall 文件夹中.但是,当我运行以下脚本时,它找不到该文件.
I am trying to find the install location of a programme using the windows registry. I have managed to find the key and the value that I need. They are found in the Software\Microsoft\Windows\CurrentVersion\Uninstall folder. However when I run the following script, it can't find the file.
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
我可以看到密钥但似乎无法访问它是怎么回事.
How is it that I can see the key but can't seem to access it.
推荐答案
您要求 SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
的 InstallLocation
值.
您需要下某个子项的InstallLocation
值SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
.
如果您想要一个特定的子项,只需将其名称添加到该路径即可.
If you want a particular subkey, just add its name to that path.
如果您想要所有这些,请使用 EnumKey
函数.像这样:
If you want all of them, use the EnumKey
function. Something like this:
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)
这篇关于Python:查看注册表以查找程序的安装位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!