Listing All The Installed Softwares In Computer Using .Net
Don't Forget To add using Microsoft.Win32
For Complete thread with screen shots see here:[snipped]
Listing All The Installed Softwares In Computer Using .Net
Don't Forget To add using Microsoft.Win32
For Complete thread with screen shots see here:[snipped]
private void Form1_Load(object sender, EventArgs e)
{
string SoftwareKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products";
RegistryKey rk = default(RegistryKey);
rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);
//string skname = null;
string sname = string.Empty;
ListView ListView1 = new ListView();
this.Controls.Add(ListView1);
ListView1.Dock = DockStyle.Fill;
ListView1.View = View.Details;
ListView1.Columns.Add("Installed Software");
foreach (string skname in rk.GetSubKeyNames())
{
try
{
sname = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("DisplayName").ToString();
ListView1.Items.Add(sname);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
} A few practical clarifications that build on 's sample and the follow-ups from and . The Installer\UserData...Products tree only shows MSI products for a specific account and often leads to nulls — many installed programs register under the Uninstall keys instead. Enumerating the Uninstall keys under both HKLM and HKCU, and reading both 32-bit and 64-bit registry views, produces a far more complete list.
Important points: always check the result of OpenSubKey for null before using it; GetValue may return null so avoid calling ToString() directly; dispose RegistryKey objects (using blocks); avoid popping a MessageBox for every exception (log or skip bad entries instead). For ASP.NET () this kind of registry enumeration usually fails in a default app pool because of permissions — run as a privileged scheduled task/service or use a client-side agent if the goal is to list software on user machines. Avoid WMI's Win32_Product because it is slow and can trigger MSI repairs.
Example helper (safe, checks both hives and registry views):
class InstalledProgram { public string Name; public string Version; public string Publisher; }
List<InstalledProgram> GetInstalledPrograms()
{
var results = new List<InstalledProgram>();
var hives = new[] { RegistryHive.LocalMachine, RegistryHive.CurrentUser };
var views = Environment.Is64BitOperatingSystem
? new[] { RegistryView.Registry64, RegistryView.Registry32 }
: new[] { RegistryView.Registry32 };
foreach (var hive in hives)
foreach (var view in views)
using (var baseKey = RegistryKey.OpenBaseKey(hive, view))
using (var uninstall = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"))
{
if (uninstall == null) continue;
foreach (var name in uninstall.GetSubKeyNames())
using (var sk = uninstall.OpenSubKey(name))
{
var disp = sk?.GetValue("DisplayName") as string;
if (string.IsNullOrWhiteSpace(disp)) continue;
results.Add(new InstalledProgram {
Name = disp,
Version = sk.GetValue("DisplayVersion") as string,
Publisher = sk.GetValue("Publisher") as string
});
}
}
return results;
} Troubleshooting: ' NullReferenceException is almost always caused by a null RegistryKey or a missing DisplayName; protect every OpenSubKey/GetValue call and skip entries that lack DisplayName.
I get an "Object reference not set to an instance of an object" error when I start the program.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.