Get A List Of Installed Applications Using LINQ And C#
To get a list of installed applications we need to look into registry. Microsoft.Win32 namespace contains objects which can be used to work with Windows Registry. In this post I will show you some code where I use the power of LINQ to retrieve and display a list of all applications installed on a machine.
The basic idea is that we iterate through a collection of RegistryKey objects within LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall. We then open the sub keys and get the DisplayName.
Here is the code:
static void DisplayInstalledApplications()
{
string registryKey =
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (Microsoft.Win32.RegistryKey key =
Registry.LocalMachine.OpenSubKey(registryKey))
{
var query = from a in
key.GetSubKeyNames()
let r = key.OpenSubKey(a)
select new
{
Application = r.GetValue("DisplayName")
};
foreach (var item in query)
{
if (item.Application != null)
Console.WriteLine(item.Application);
}
}
}
I can also make this a bit more LINQed by removing the foreach loop. It just adds a bit more C# 3.0 flavour to the code and does the retrieval and writing to console in one line.
static void DisplayInstalledApplications2()
{
string registryKey =
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (Microsoft.Win32.RegistryKey key =
Registry.LocalMachine.OpenSubKey(registryKey))
{
(from a in key.GetSubKeyNames()
let r = key.OpenSubKey(a)
select new
{
Application = r.GetValue("DisplayName")
}).ToList()
.FindAll(c => c.Application != null)
.ForEach(c => Console.WriteLine(c.Application));
}
}
I hope you found this post useful. If yes, then do not forget to subscribe to OneDotNetWay Feed .
17 Responses to Get A List Of Installed Applications Using LINQ And C#
Leave a Reply Cancel reply
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML


[...] video every week and this week they paid a visit to One .Net Way. They mentioned my post about Retrieving a list of applications using LINQ in their news video. I am very happy to see One .Net Way mentioned on Channel 9. It feels good when [...]
This is exactly what I was looking for. And getting the list using LINQ makes it even better.
Looks like you have just changed the look of your site. It looks more professional now.
Rajesh,
I am glad that you found this post useful. Thank you for your comment on the new theme. I was looking for something which would allow me to give this site a portal-type look. Finally I found the right theme.
thats a lot for this helpful code snippet… save so much of my time, since i am beginner to programming…
thanks again Deepak,
anil bhatt…
Anil,
I am happy to know that this post helped you.
Excellent snippet!
Thanks Taka.
Such way you don’t get applications that are installed for the specific user. You need to look in one more place in the registry:
HKEY_USERS\S-1-5-21-…-7206\Software\Microsoft\Windows\CurrentVersion\Uninstall
for every user that exists in the OS
Or, much more compact:
string registryKey = @”SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”;
RegistryKey key = LocalMachine.OpenSubKey(registryKey);
foreach (String a in key.GetSubKeyNames()) {
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue(“DisplayName”));
}
nice one NT
for 64bit OS you also need to search this key:
“SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”
so the whole code that works for me is here (may be simplified, I don’t know):
string registryKey = @”SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”;
RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue(“DisplayName”));
}
registryKey = @”SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”;
key = Registry.LocalMachine.OpenSubKey(registryKey);
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue(“DisplayName”));
}
Thanks Skroslak.
skroslak thank you for the 64 bit location!!
[...] Get A List Of Installed Applications Using LINQ And C# [...]
Thanks for that example. Works perfect in Windows 7. Congratulations!!
Nico, you are most welcome.