當我說「已安裝的應用程序」時,我基本上是指在[控制面板] - > [添加/刪除程序]中可見的任何應用程序。如何在Windows XP中列舉/列出所有已安裝的應用程序?
我寧願用Python做,但C或C++也很好。
當我說「已安裝的應用程序」時,我基本上是指在[控制面板] - > [添加/刪除程序]中可見的任何應用程序。如何在Windows XP中列舉/列出所有已安裝的應用程序?
我寧願用Python做,但C或C++也很好。
如果你的意思是在添加所示的安裝的應用程序列表\刪除控制面板程序,您可以在註冊表項中找到它:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
more info about how the registry tree is structured can be found here。
您需要在python中使用winreg API來讀取註冊表中的值。
當。你打敗了我。 – 2009-04-29 14:07:23
查看Win32_Product WMI(Windows Management Instrumentation)類。 Here's a tutorial在Python中使用WMI。
控制面板使用Win32 COM api,這是官方方法(請參閱Google Groups,Win32)
永遠不要依賴註冊表。
該Microsoft Script Repository有一個script for listing all installed software。爲獲得在xp和Win7使用WMI已安裝軟件的列表
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Product")
for objItem in colItems:
print "Caption: ", objItem.Caption
print "Description: ", objItem.Description
print "Identifying Number: ", objItem.IdentifyingNumber
print "Install Date: ", objItem.InstallDate
print "Install Date 2: ", objItem.InstallDate2
print "Install Location: ", objItem.InstallLocation
print "Install State: ", objItem.InstallState
print "Name: ", objItem.Name
print "Package Cache: ", objItem.PackageCache
print "SKU Number: ", objItem.SKUNumber
print "Vendor: ", objItem.Vendor
print "Version: ", objItem.Version
C#.NET代碼(WMI是在Win7的唯一途徑),我見過的最好的基於註冊表的實現
WqlObjectQuery wqlQuery =
new WqlObjectQuery("SELECT * FROM Win32_Product");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(wqlQuery);
foreach (ManagementObject software in searcher.Get()) {
Console.WriteLine(software["Caption"]);
}
是克里斯賴特(Chris128)發佈在http://www.vbforums.com/showthread.php?t=598355。它使用多個註冊表項,比當前發佈的任何答案複雜得多。它似乎產生相同的結果添加/刪除程序的應用程序,並像ARP應用程序它也提供了一個選項,包括更新。
儘管它在VB.NET中實現,但應該很容易轉換爲其他.NET語言,如C#或IronPython。我想如果這是你想要的,首先轉換爲IronPython應該使它能夠很容易地移植到常規Python,但是我只將它自己轉換爲C#,然後清理了一下代碼。
只有一個小錯誤需要指出:即使提取它,GetUserInstallerKeyPrograms()也不會將用戶程序的版本添加到列表中。這很容易解決。
如何定義「已安裝的應用程序」? – 2009-04-29 14:03:36
澄清添加 – sharkin 2009-04-29 14:05:48