|
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 .
Leave a Reply
9399 views, 3 so far
today |
Follow Discussion
14 Responses to “Get A List Of Installed Applications Using LINQ And C#”
Trackbacks
- Channel 9 Visits One .Net Way | One .Net Way September 9th, 2008
Leave a Reply
Get Updates By Email
Popular Post
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Free Icons And Images With Visual Studio 2008
- Windows 7 Control Panel In Classic Mode
- Dynamic Sort With LINQ
- Use SqlConnection With LINQ To SQL
- StyleCop Tutorial
- Write To Vista Event Log Using C#
- More Details Emerge On Microsoft Master Certification
Tag Cloud
Code Snippets
- Get Current Windows User In C#
- Get Width And Height Of Image In C#
- Get Windows Registry Size With WMI And C#
- Reverse Array Elements Using C#
- Convert Hexadecimal To Number In C#
- Get Free Disk Space Using T-SQL
- SQL Server 2008 – Get All Indexes In A Database
- Get Name Of Current Executing Assembly In C#
- Get CD Or DVD Drive Information Using WMI And C#
- Get Last Row From Table Using LINQ To SQL


September 10th, 2008 at 9:27 pm
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.
September 11th, 2008 at 10:55 am
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.
November 3rd, 2008 at 8:35 pm
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…
November 3rd, 2008 at 8:52 pm
Anil,
I am happy to know that this post helped you.
March 2nd, 2009 at 9:03 pm
Excellent snippet!
March 2nd, 2009 at 9:11 pm
Thanks Taka.
April 5th, 2009 at 4:47 pm
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
June 4th, 2009 at 9:15 pm
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”));
}
June 4th, 2009 at 10:13 pm
nice one NT
October 12th, 2009 at 4:39 am
for 64bit OS you also need to search this key:
“SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”
October 12th, 2009 at 4:53 am
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”));
}
October 23rd, 2009 at 12:38 pm
Thanks Skroslak.
February 27th, 2010 at 1:39 am
skroslak thank you for the 64 bit location!!