Home > Backend Development > C++ > How Can I Retrieve a List of Installed Applications in C#?

How Can I Retrieve a List of Installed Applications in C#?

Barbara Streisand
Release: 2025-01-24 23:52:10
Original
352 people have browsed it

How Can I Retrieve a List of Installed Applications in C#?

Use C# to get system installed applications

Question:

How to determine the applications installed on the system using C# code?

Solution:

To get a list of installed applications on your system using C#, you can use the registry or WMI (Windows Management Instrumentation).

Registry-based method:

Iterating through the registry key "SOFTWAREMicrosoftWindowsCurrentVersionUninstall" can provide a complete list of installed applications. Each subkey represents a different application, and the "DisplayName" value contains the name of the application.

WMI method:

A slower but feasible alternative is to use WMI through the ManagementObjectSearcher object. The query "SELECT * FROM Win32_Product" will retrieve a list of installed programs. The "Name" property of each ManagementObject represents the name of the application.

Code snippet:

Based on registry:

<code class="language-csharp">string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
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"));
        }
    }
}</code>
Copy after login

Based on WMI:

<code class="language-csharp">ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach (ManagementObject mo in mos.Get())
{
    Console.WriteLine(mo["Name"]);
}</code>
Copy after login

Note:

Registry-based methods may also capture Windows updates and components. WMI, although slower, may miss installed applications for all users. Depending on your needs, you can choose the appropriate method.

The above is the detailed content of How Can I Retrieve a List of Installed Applications in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template