获取系统中已安装的应用程序 [英] Get installed applications in a system

查看:26
本文介绍了获取系统中已安装的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#代码获取系统中安装的应用程序?

How to get the applications installed in the system using c# code?

推荐答案

遍历注册表项SOFTWAREMicrosoftWindowsCurrentVersionUninstall"似乎给出了已安装应用程序的完整列表.

Iterating through the registry key "SOFTWAREMicrosoftWindowsCurrentVersionUninstall" seems to give a comprehensive list of installed applications.

除了下面的例子,你可以找到与我所做的类似的版本这里.

Aside from the example below, you can find a similar version to what I've done here.

这是一个粗略的例子,您可能想要做一些事情来去除提供的第二个链接中的空白行.

This is a rough example, you'll probaby want to do something to strip out blank rows like in the 2nd link provided.

string registry_key = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
            Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}

或者,您可以使用 WMI,如前所述:

Alternatively, you can use WMI as has been mentioned:

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

但这执行起来相当慢,而且我听说它可能只列出安装在ALLUSERS"下的程序,尽管这可能不正确.它还忽略了 Windows 组件 &更新,这可能对您有用.

But this is rather slower to execute, and I've heard it may only list programs installed under "ALLUSERS", though that may be incorrect. It also ignores the Windows components & updates, which may be handy for you.

这篇关于获取系统中已安装的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆