DataTable dtSoftwares = new DataTable();

dtSoftwares.Columns.Add(new DataColumn("Name"));

dtSoftwares.Columns.Add(new DataColumn("Installed location"));

dtSoftwares.Columns.Add(new DataColumn("Publisher"));

//The registry key will be held in a string SoftwareKey.

string SoftwareKey = @"SOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products";

RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);

foreach (string skName in rk.GetSubKeyNames())

{

try

{

//Get sub keys

object name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName");

object installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation");

//InstallProperties

object publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher");

object uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString");

//Add the Software information to lstPrograms

if (name.ToString() != "")

{

DataRow dtnewRow = dtSoftwares.NewRow();

//Set Text Property to Name of Software

dtnewRow["Name"] = name.ToString();

//Add Install Location

dtnewRow["Installed location"] = installocation.ToString();

//Add Publisher

dtnewRow["Publisher"] = publisher.ToString();

dtSoftwares.Rows.Add(dtnewRow);

}

}

catch (Exception)

{

}

}

dataGridView1.DataSource = dtSoftwares;

Advertisements