Get List of Installed Applications of System in C#





5.00/5 (12 votes)
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:
- Add a
listviewer
and a button to your design form. - We want use "
RegistryKey
" class, so add "using Microsoft.Win32
" to your projectusing
s. - Put this code in your button click event:
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 useDisplayName
andEstimatedSize
subkeys which show usName
andSize
of all installed apps, and at the end, the result will be shown inlistviewer
. - 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:
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!