如何使用c#获取所有已安装的Windows应用程序

本文关键字:安装 Windows 应用程序 何使用 获取 | 更新日期: 2023-09-27 18:09:02

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

请帮我找到这个解决方案。

如何使用c#获取所有已安装的Windows应用程序

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

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

另一种可能性是使用SOFTWARE'Microsoft'Windows'CurrentVersion'Uninstall for 32位应用程序和HKEY_LOCAL_MACHINE'SOFTWARE'Wow6432Node'Microsoft'Windows'CurrentVersion'Uninstall for 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"));
        }
    }
}

希望能有所帮助。