Click here to Skip to main content
15,889,116 members
Articles / Programming Languages / C#
Tip/Trick

Get List of Installed Applications of System in C#

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
6 Jun 2014CPOL 78.7K   6K   21   6
How to list the installed applications of your system and their setup details in C# language

Introduction

In this tip, we will explain how to list the installed applications of your system and their setup details in C# language.

Background

This tip is based on a Registry key whose address is HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall and you can find there many subkeys which help us to have different details of installed applications.

Using the Code

So for doing what we want, we must follow the steps given below:

  1. Add a listviewer and a button to your design form.
  2. We want use "RegistryKey" class, so add "using Microsoft.Win32" to your project usings.
  3. Put this code in your button click event:
    C#
    string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
                {
                    foreach (string skName in rk.GetSubKeyNames())
                    {
                        using (RegistryKey sk = rk.OpenSubKey(skName))
                        {
                            try
                            {
    
                                var displayName = sk.GetValue("DisplayName");
                                var size = sk.GetValue("EstimatedSize");
    
                                ListViewItem item;
                                if (displayName != null)
                                {
                                    if (size != null)
                                        item = new ListViewItem(new string[] {displayName.ToString(), 
                                                           size.ToString()});
                                    else
                                        item = new ListViewItem(new string[] { displayName.ToString() });
                                    lstDisplayHardware.Items.Add(item);
                                }
                            }
                            catch (Exception ex)
                            { }
                        }
                    }
                    label1.Text += " (" + lstDisplayHardware.Items.Count.ToString() + ")";
                }  

    Explanation: In this code, at first, we defined a registry command in a specific address (uninstallKey). Then, we use DisplayName and EstimatedSize subkeys which show us Name and Size of all installed apps, and at the end, the result will be shown in listviewer.

  4. You can use all subkeys in the below list:
    Value / Windows Installer property
    
    DisplayName ==> ProductName property
    DisplayVersion ==> Derived from ProductVersion property
    Publisher ==> Manufacturer property
    VersionMinor ==> Derived from ProductVersion property
    VersionMajor ==> Derived from ProductVersion property
    Version ==> Derived from ProductVersion property
    HelpLink ==> ARPHELPLINK property
    HelpTelephone ==> ARPHELPTELEPHONE property
    InstallDate ==> The last time this product received service. 
    The value of this property is replaced each time a patch is applied or removed from 
    the product or the /v Command-Line Option is used to repair the product. 
    If the product has received no repairs or patches this property contains 
    the time this product was installed on this computer.
    InstallLocation ==> ARPINSTALLLOCATION property
    InstallSource ==> SourceDir property
    URLInfoAbout ==> ARPURLINFOABOUT property
    URLUpdateInfo ==> ARPURLUPDATEINFO property
    AuthorizedCDFPrefix ==> ARPAUTHORIZEDCDFPREFIX property
    Comments ==> Comments provided to the Add or Remove Programs control panel.
    Contact ==> Contact provided to the Add or Remove Programs control panel.
    EstimatedSize ==> Determined and set by the Windows Installer.
    Language ==> ProductLanguage property
    ModifyPath ==> Determined and set by the Windows Installer.
    Readme ==> Readme provided to the Add or Remove Programs control panel.
    UninstallString ==> Determined and set by Windows Installer.
    SettingsIdentifier ==> MSIARPSETTINGSIDENTIFIER property

Source: http://msdn.microsoft.com/en-us/library/aa372105(v=vs.85).aspx

Note: Also, you can have this method in your code instead of the above code:

C#
try
    {
      string[] row = { sk.GetValue("DisplayName").ToString() , 
      sk.GetValue("EstematedSize").ToString()};
      var listViewItem = new ListViewItem(row);
      lstDisplayHardware.Items.Add(listViewItem);
    }

catch (Exception ex)
    { }

Now you build your program!

Image 1

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionViewing installed Windows apps Pin
Modz535-Sep-22 3:23
Modz535-Sep-22 3:23 
Questionif registry is locked then? Pin
Member 128073539-Mar-17 0:08
Member 128073539-Mar-17 0:08 
QuestionNeeds a second registry location for 64-bit OSes Pin
jfos15-Jun-14 13:44
jfos15-Jun-14 13:44 
After trying your program on my computer, I compared the results with Window's "Uninstall or change a program" control panel and I noticed that there were some glaring omissions to the list created. After doing a bit of leg work, I finally found that that on 64-bit OSes you also need to query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall also.

After I ran the program with that key, I found my "missing" programs. You probably don't have to specifically check for a 64-bit version of Windows, but just check and see if opening the registry location (OpenSubKey) returns null or not.

EDIT: Oddly, using the Wow6432Node key location seems to return duplicates for some reason too. I didn't notice it at first since I wasn't sorting the list originally. And these are duplicates in Wow6432Node only, not dups between the two registry keys (although those may exist too). They are not exact duplicates though. One entry may have an install date and the other does not. One may have one estimated size and the other may be different, etc. In the case of the different sizes, Windows seems to be reporting the one of the two sizes (larger one?), not the combined value.

Thanks,
Jim

modified 15-Jun-14 19:58pm.

QuestionYou may not have registry permissions Pin
FatCatProgrammer6-Jun-14 3:34
FatCatProgrammer6-Jun-14 3:34 
GeneralThank you Pin
Emre Ataseven6-Jun-14 3:11
professionalEmre Ataseven6-Jun-14 3:11 
AnswerRe: Thank you Pin
Amir Mohammad Nasrollahi6-Jun-14 3:19
Amir Mohammad Nasrollahi6-Jun-14 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.