gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:38:26 27 4
gpt4 key购买 nike

我正在尝试使用 Windows 注册表查找程序的安装位置。我已经找到了我需要的 key 和值(value)。它们位于 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

为什么我可以看到 key ,但似乎无法访问它。

最佳答案

您要求提供 SOFTWARE\Microsoft\Windows\CurrentVersion\UninstallInstallLocation 值。

您需要SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall某个子项InstallLocation值。

如果您想要特定的子项,只需将其名称添加到该路径即可。

如果您想要全部,请使用 EnumKey功能。像这样的事情:

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:查看注册表以查找程序的安装位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21090325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com