【问题标题】:how to get all installed applications of windows using c#如何使用c#获取所有已安装的windows应用程序
【发布时间】:2015-08-20 05:10:31
【问题描述】:

我已尝试HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 将所有应用程序安装在我的计算机中并获取应用程序列表,但我需要获取 Windows 的添加或删除程序功能中列出的所有应用程序。

请帮我解决这个问题。

【问题讨论】:

  • 请格式化您的问题。
  • 我认为注册表不会遗漏您在“添加或删除程序”中看到的任何内容。还有其他的cmets吗?
  • 是的,我同意@Simonzhao。该注册表位置是添加或删除程序检查已安装软件的唯一位置。
  • @ThePcLuddite 不正确。 “添加或删除程序”也咨询其他位置。如果您想显示与“添加或删除程序”相同的内容,you can ask for its contents via the shell programming model
  • @RaymondChen 它还使用哪些其他位置?链接的文章只是谈论从控制面板小程序本身获取列表。

标签: c# windows registry


【解决方案1】:

我认为你可以像这样使用 WMI:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach(ManagementObject mgmtObjectin searcher .Get())
{
    Console.WriteLine(mgmtObjectin ["Name"]);
}

另一种可能性是将 SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 用于 32 位应用程序,将 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall 用于 64 位应用程序并合并列表,我认为您的代码应该看起来喜欢:

string registry_key_32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string registry_key_64 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";

using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key_32))
{
    foreach(string name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(name))
        {
            Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}
// And...
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key_64))
{
    foreach(string name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(name))
        {
            Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}

希望对你有帮助。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-09-17
  • 1970-01-01
  • 1970-01-01
  • 2015-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
相关资源
最近更新 更多