How to get Installed Programs List.
This resource introduce how to retrive installed programes in Computer.
Through this code user can retrive all software list which is installed and software's Name, Version and Publisher; Through Windows Registry. And Display details in Data Grid View in Window Application.
This code helps us to retrive the Installed Software from local computer.
In this code I used following NamespaceNameSpaces
using System;
using System.Data;
using System.Windows.Forms;
using Microsoft.Win32;
I have taken One button and One GridView. And OnClick Event of Button I have write this code for Getting List of Installed Software. Whole Code Of Button Click Event
string DisplayName = null;
string RegistryKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnInstall";
DataTable dt = new DataTable();
dt.Columns.Add("Software Name", typeof(string));
dt.Columns.Add("Software Version", typeof(string));
dt.Columns.Add("Software Publisher", typeof(string));
DataRow dr = null;
using (RegistryKey RegisrtyKey1 = Registry.LocalMachine.OpenSubKey(RegistryKey))
{
foreach (var varName in RegisrtyKey1.GetSubKeyNames())
{
using (RegistryKey RegistryKey2 = RegisrtyKey1.OpenSubKey(varName))
{
DisplayName = Convert.ToString(RegistryKey2.GetValue("DisplayName"));
if (DisplayName.Equals(""))
{
continue;
}
else
{
dr = dt.NewRow();
dr[0] = (string)RegistryKey2.GetValue("DisplayName");
if (RegistryKey2.GetValue("DisplayVersion") == null)
dr[1] = "";
else
dr[1] = (string)RegistryKey2.GetValue("DisplayVersion");
dr[2] = (string)RegistryKey2.GetValue("Publisher");
dt.Rows.Add(dr);
}
}
}
}
GridSoftwares.Columns.Clear();
GridSoftwares.DataSource = dt;
Now Let me know you brief description of the code.
string DisplayName = null;
string RegistryKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnInstall";
DataTable dt = new DataTable();
dt.Columns.Add("Software Name", typeof(string));
dt.Columns.Add("Software Version", typeof(string));
dt.Columns.Add("Software Publisher", typeof(string));
DataRow dr = null;
In Above code I have taken one null string and One Static string of registry path from where we can fetch the details of installed software. And I have created A DataTable with three columns named Software Name, Software Version and Softwaer Publisher.
using (RegistryKey RegisrtyKey1 = Registry.LocalMachine.OpenSubKey(RegistryKey))
{
foreach (var varName in RegisrtyKey1.GetSubKeyNames())
{
using (RegistryKey RegistryKey2 = RegisrtyKey1.OpenSubKey(varName))
{
DisplayName = Convert.ToString(RegistryKey2.GetValue("DisplayName"));
if (DisplayName.Equals(""))
{
continue;
}
else
{
dr = dt.NewRow();
dr[0] = (string)RegistryKey2.GetValue("DisplayName");
if (RegistryKey2.GetValue("DisplayVersion") == null)
dr[1] = "";
else
dr[1] = (string)RegistryKey2.GetValue("DisplayVersion");
dr[2] = (string)RegistryKey2.GetValue("Publisher");
dt.Rows.Add(dr);
}
}
}
}
In Above code I have open registry subkey to retrive installed software's Details. And Create a DataRow and add it in DataTable. Through above code we can get the list of Installed software in DataTable. And Now I will assign that datatable to DataGrid like this
GridSoftwares.Columns.Clear();
GridSoftwares.DataSource = dt;
Now user can view in grid view the details of Installed Software.
Thank you it is perfect tutorial.
i have a question.
you write DisplayName but i want to access the "DisplayLocation".
I write "DisplayLocation" but null.
What should write to take location?