【问题标题】:In C# .NET 2.0 or greater, how to get list of all installed applications on Vista PC在 C# .NET 2.0 或更高版本中,如何获取 Vista PC 上所有已安装应用程序的列表
【发布时间】:2009-10-21 20:36:33
【问题描述】:

使用 C# .NET 2.0 或更高版本和 Visual Studio 2008,如何在 Windows Vista PC 上生成所有已安装应用程序的列表?

我的动机是获取所有已安装应用程序的文本文件,我可以保存并保留它,这样当我重建机器时,我就有了所有旧应用程序的列表。

这个问题的第二部分有点像 SuperUser.com 的事情,但希望第一部分算作“编程”。

谢谢

【问题讨论】:

    标签: c# .net installation


    【解决方案1】:

    【讨论】:

    • 当然,这只会返回注册表中列出的应用程序列表。通过 XCOPY 部署部署的应用程序不会显示。
    • 是的,可能不是所有 Adam 的应用都会出现在注册表中,因为它们可能是复制到磁盘而不是安装的应用。
    【解决方案2】:

    以下内容将为您提供所有用户已安装的应用程序。做同样的事情 Registry.CurrentUser 也是如此:

        RegistryKey uninstall = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
        List<string> applicationList = new List<string>();
        foreach (string subKeyName in uninstall.GetSubKeyNames())
        {
            RegistryKey subKey = uninstall.OpenSubKey(subKeyName);
            string applicationName = subKey.GetValue("DisplayName", String.Empty).ToString();
            if (!String.IsNullOrEmpty(applicationName))
            {
                applicationList.Add(applicationName);
            }
            subKey.Close();
        }
    
        uninstall.Close();
    
        applicationList.Sort();
    
        foreach (string name in applicationList)
        {
            Console.WriteLine(name);    
        }
    

    免责声明:我的示例中没有空值/错误检查!

    【讨论】:

      【解决方案3】:

      the source code of this library

      foreach(var info in BlackFox.Win32.UninstallInformations.Informations.GetInformations())
      {
          Console.WriteLine(info.ToString());
      }
      

      【讨论】:

        【解决方案4】:

        还必须考虑不同级别的安装。

        • 自安装以来,应用可能已对其进行过处理(删除等)。
        • 有些应用不“安装”,而是作为裸二进制文件运行。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2023-03-20
          • 2010-11-25
          • 2015-01-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多