Thursday, August 6, 2009

I have a whopping 693 programs on my XP development machine. How many do you have?

You can simply find out by creating a C# console application, cutting the following, and hitting F5.

using System;
using System.Collections.Generic;
using Microsoft.Win32;


. . .


static void Main(string[] args)
{
List<string> programs = GetInstalledPrograms();
foreach (string program in programs)
{
Console.WriteLine(program);
}
Console.WriteLine("Total - " + programs.Count.ToString());
Console.Read();
}

private static List<string> GetInstalledPrograms()
{
string installKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
List<string> displayNames = new List<string>();
string[] subkeyNames = Registry.LocalMachine.OpenSubKey(installKey).GetSubKeyNames();
foreach (string subkeyName in subkeyNames)
{
string displayName = (string)Registry.LocalMachine.OpenSubKey(installKey + "\\" + subkeyName).GetValue("DisplayName");
if (!string.IsNullOrEmpty(displayName))
{
displayName += "\t" + subkeyName;
}
else
{
displayName = subkeyName;
}
displayNames.Add(displayName);
}
displayNames.Sort();
return displayNames;
}

No comments:

Post a Comment