I'm trying to create certain functionality within my C# winforms application.
I want to be able to replicate what programs like Discord, NVidia GeForce Experience, and Steam have created in their apps. Which is the ability to display a list of your installed applications while linking them to their respectable executable files.
Discord scans your system so it knows about every application you have installed and displays which game you are currently playing in its interface without any input from the user. (This is the most relevant functionality to what I'm after)
I know how to check through the registry in C# to return a list of installed applications. I've seen many Stackoverflow questions asked about that, it is not what I need help with.
What I'm having trouble with is trying to extract information from that list to tell me where each one is installed or has its .exe file which runs the game.
Through my research into this, I've found that there isn't really a reliable way to do that through those registry keys. Even though some subkeys have a value named 'InstallLocation', half of them don't have an actual path filled in.
This is the code I have so far. (I know this isn't the only place programs could be installed, I just want a to create a working demo and then look through currentUser and the other paths where apps can be installed.) :
static void Main(string[] args)
{
getPrograms();
}
private static void getPrograms()
{
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
foreach (string subkey_name in key.GetSubKeyNames())
{
using (RegistryKey subkey = key.OpenSubKey(subkey_name))
{
Console.WriteLine(subkey.GetValue("DisplayName"));
Console.WriteLine("-------------------------");
}
}
}
}
This works to display installed programs, yet half of the subkeys dont even have their DisplayName value set.
Would scanning for every .exe on the system be a better way to approach this, even though I would probably have to weed through installers and the like?
TL;DR: I'm trying to display a list of installed applications. When one is selected by the user, it's placed on a watch list so *my* application knows when the selected application is running and when it has closed down.
Thank you in advance for any and all help or advice given.
EDIT: Just to add, I have the code needed to watch for when a selected application is running and when it closes down. That all works fine. I just want to allow for the option to select from a list instead of filling in input fields for the application name and .exe location.
EDIT2: I know the code I have provided is for a console app. I am trying to build the functionality in isolation by itself and then integrate it with my existing winforms app.