I am sorry if the title for my question is not apt.
I am a newbie to the programming side and trying to write a console app for getting all the installed apps on the computer from registry.
Here is my code.
class Program
{
static void Main(string[] args)
{
Console.Title = "Windows App Finder - Finds all the installed apps on the station";
List<AppDetails> apps = new List<AppDetails>();
apps = GetInstalledApps();
ListAllApps(apps);
Console.WriteLine("\nPress any key to exit.");
Console.ReadLine();
}
private static List<AppDetails> GetInstalledApps()
{
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
AppDetails appInfo = new AppDetails();
List<AppDetails> apps = new List<AppDetails>();
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
foreach (string subkey_name in key.GetSubKeyNames())
{
using (RegistryKey subkey = key.OpenSubKey(subkey_name))
{
appInfo.appName = (string)subkey.GetValue("DisplayName");
appInfo.publisher = (string)subkey.GetValue("Publisher");
appInfo.appVersion = (string)subkey.GetValue("DisplayVersion");
if (appInfo.appName != null )
{
apps.Add(appInfo);
}
}
}
}
return apps;
}
private static void ListAllApps(List<AppDetails> appDetails)
{
int i = 0;
foreach (AppDetails appDetail in appDetails)
{
Console.WriteLine(i.ToString() + ". Name: " + appDetail.appName + " Version: " + appDetail.appVersion + " Publisher: " + appDetail.publisher);
i++;
}
}
}
public class AppDetails
{
public string appName { get; set; }
public string appVersion {get; set;}
public string publisher {get;set;}
public DateTime installDate { get; set; }
}
}
This code returns https://i.sstatic.net/tKtNr.png Single app name repeated multiple times. What is wrong with this piece of code.
Thanks in advance