Hi Member,
I think Dave Kreskowiak is correct that your approach won't catch all installed software reliably.
Anyway if you want to try this approach: here is some code that does the seaching part you asked for. (I don't think you will get the associated install paths easily, I even didn't try.., but the example code could be changed to give something else back than just the Display names...)
using System;
using System.Collections.Generic;
using Microsoft.Win32;
namespace GetInstalledSoftware
{
class Program
{
static void Main(string[] args)
{
string[] astrMatches = GetAllInstalledSoftware("Microsoft");
foreach (string strDisplayName in astrMatches)
{
Console.WriteLine(strDisplayName);
}
Console.ReadKey();
}
static string[] GetAllInstalledSoftware(string strPrefix)
{
const string strUNINSTALL_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
List<string> listMatches = new List<string>();
foreach (string strSubKey in Registry.LocalMachine.OpenSubKey(strUNINSTALL_KEY).GetSubKeyNames())
{
object objValue = Registry.LocalMachine.OpenSubKey(strUNINSTALL_KEY + @"\" + strSubKey).GetValue("DisplayName");
if (objValue != null)
{
string strDisplayName = objValue.ToString();
if (strDisplayName.StartsWith(strPrefix))
{
listMatches.Add(strDisplayName);
}
}
}
return listMatches.ToArray();
}
}
}
But be aware that I don't think this is a "good" solution: reading registry, relying on the "DisplayName" property (which isn't always set), relying on the prefix (not seaching inside the Display string) etc. Anyway, I hope you don't use that code for any real world scenario (It seemed you even had problems to understand the example code you gave - or copied... So my general advice for beginners: leave the registry alone :-)
If you have any further questions - feel free to ask.
Kind regards
Johannes