日期:2014-05-17  浏览次数:20909 次

获取计算机已安装软件列表
Dear all,
  最近小弟在做一个应用程序,就是仿造360软件管家,获取计算机里已安装软件列表,
  现思路如下,根据注册表路径:
  针对x86系统,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  针对x64系统,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
  分别获取已安装软件列表,然后按照以下步骤进行处理:
  1.剔除service项,重复项,已安装补丁,如KB开头的子项(计划中,未能实现)
  2.合并x86,x64.最终得到软件列表数据
  遇到的问题,
  1.该实现思路是否正确?
  2.思路正确的前提下,如何解决识别为service,重复项,补丁等子项

  恳请大侠指教?
TOM
  
  
 

------解决方案--------------------
C# code
Microsoft.Win32.RegistryKey   rk   =   Microsoft.Win32.Registry.LocalMachine.OpenSubKey( "SOFTWARE ");
String   []   names   =   rk.GetSubKeyNames();
foreach   (String   s   in   names)  
{
//输出吧....
}

------解决方案--------------------
可以用Installer API,详细文档见http://msdn.microsoft.com/en-us/library/aa369426(v=VS.85).aspx。

C# code

static void Main()
{
    StringBuilder result = new StringBuilder();
    for (int index = 0; ; index++)
    {
        StringBuilder productCode = new StringBuilder(39);
        if (MsiEnumProducts(index, productCode) != 0)
        {
            break;
        }

        foreach (string property in new string[] { "ProductName", "Publisher", "VersionString", })
        {
            int charCount = 512;
            StringBuilder value = new StringBuilder(charCount);

            if (MsiGetProductInfo(productCode.ToString(), property, value, ref charCount) == 0)
            {
                value.Length = charCount;
                result.AppendLine(value.ToString());
            }
        }
        result.AppendLine();
    }
    Console.WriteLine(result.ToString());
}
       
[DllImport("msi.dll", SetLastError = true)]
static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);

[DllImport("msi.dll", SetLastError = true)]
static extern int MsiGetProductInfo(string szProduct, string szProperty, StringBuilder lpValueBuf, ref int pcchValueBuf);

------解决方案--------------------
c# 获取已安装程序列表