'适当' &在 Python 中获取所有已安装 Windows 程序的可靠方法? [英] 'proper' & reliable way to get all installed windows programs in Python?

查看:43
本文介绍了'适当' &在 Python 中获取所有已安装 Windows 程序的可靠方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了多种在 Python 中检索 WinXP+ 上已安装程序的方法.什么是正确最可靠的方法?

I've seen numerous ways of retrieving installed programs on WinXP+ in python. What is the proper and most robust way of doing this?

目前我正在访问 HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall 并从那里读取每个键以获取列表.(有人告诉我这不是正确的做事方式)我也看到了使用 WMI/Win32com 来执行此操作的示例,但也看到了评论以及 WMI 可能的那些实现在某些机器上被关闭,这不是一个非常可靠的解决方案.

Currently I'm accessing HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall and reading each of the keys from there to get a list. (I've been told this isn't the proper way of doing things) I've seen examples of using WMI/Win32com to do this as well but have seen comments along with those implementations that WMI might be turned off on certain machines and that it's not a very reliable solution.

是否有一种既正确又可靠的方法来获取已安装程序的列表?我见过的 WMI 示例都没有在这台机器上运行(因此我不愿意使用它,我只运行 WinFLP;这是 XP 的一个剥离版本.)

Is there a method which is both proper, and reliable to get a list of installed programs? None of the WMI examples I've seen have worked on this machine (hence my reluctance to use it, I'm only running WinFLP; which is a stripped vers of XP.)

我似乎还找到了 TechNet 文章,我的搜索已经找到该文章,该文章提供了对我的问题的类似答案:http://gallery.technet.microsoft.com/ScriptCenter/en-us/154dcae0-57a1-4c6e-8f9f-b2159044>Noteb215904485平台下列出的 Vista/7 非常清楚地说不"......不会工作.因此,WMI 交易似乎是行不通的...

I seem to have also found the TechNet article which my searches have turned up which is provided to a similar answer on my question: http://gallery.technet.microsoft.com/ScriptCenter/en-us/154dcae0-57a1-4c6e-8f9f-b215904485b7 Note that Vista/7 listed under Platforms very clearly says "Nope"...won't work. So the WMI deal seems like it's a no-go...

能够检索已安装的路径也是一个好处,因为现在我当前的代码没有考虑安装在另一个驱动器上或非默认目录中的人.

Being able to retrieve the installed path would be an upside as well, as right now my current code does not account for someone installing on another drive, or in a non-default directory.

推荐答案

您提到的 technet 脚本在 Win 7(使用 Python 2.5 32 位)下完美运行,我真的不明白为什么不应该这样做.

The technet script you refer to perfectly works under Win 7 (with Python 2.5 32bits), and I really cannot see why it shouldn't.

实际上,WMI 方法的真正弱点是它只列出通过 Windows 安装程序安装的产品.所以它不会给你完整的列表.许多程序使用不同的安装程序.只需比较 (Select * from Win32_Product) 和控制面板中显示的结果之间的结果.因此,除非您确定在您的列表中插入您的程序安装了 MSI,否则 WMI 绝对不是一个答案.

Actually, the real weakness of the WMI approach is that it only lists products installed through the Windows Installer. So it's will not give you the full list. Many programs use different installers. Just compare the results between the (Select * from Win32_Product) and what is displayed in the Control Panel. So, unless you are sure that the program that interset you in your listing are installed with MSI, WMI is definitely not an answer.

所以它可能不是很pythonic,但据我所知,最好的方法是像你一样使用注册表.这实际上是控制面板的工作方式,因此至少 Windows 认为这是最可靠的方式.

So it may be not very pythonic, but the best way, as far as I know, is to use the registry as you've done. This is actually how the control panel works, so at least Windows considers it to be the most robust way to do it.

这篇关于'适当' &在 Python 中获取所有已安装 Windows 程序的可靠方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆