'proper' & reliable way to get all installed windows programs in Python?

前端 未结 2 1521
日久生厌
日久生厌 2021-02-03 11:03

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

Currently I\'m ac

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 11:37

    WMI is the correct way to look for installed programs as it will work across different versions of the OS and will be supported going forward. Looking for specific regkeys may work fine for specific versions of Windows but is not guaranteed to work in the future. Here is some simple python code to check for Box Sync which I just tried on Windows 7. Note that not all fields will be available for every product so be aware these will be 'None.'

    import wmi
    w = wmi.WMI()
    for p in w.Win32_Product():
        if 'Box, Inc.' == p.Vendor and p.Caption and 'Box Sync' in p.Caption:
            print 'Installed {}'.format(p.Version)
    

    The downside I have seen with WMI is it is very slow to start up.

提交回复
热议问题