Sometimes there is a need to find information about what software is installed on your computer. For example, we want to know, if anyone has already installed the program and where it is installed. This knowledge is needed, example, if you add a file to a directory with the program already installed. The simplest example is to write different kinds of plugins. The problem does not occur if the application has been installed in the default directory, we know, but this can no longer guarantee.
To find a list of programs installed on your computer, you should review the following registry branch HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall. Code to review this branch is as follows:
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"), InstallLocation = r.GetValue("InstallLocation") }; foreach (var item in query) { if (item.Application != null) { Console.WriteLine(item.Application + " - " + item.InstallLocation); } } }
The above code displays the names of the installed program and path to it. Of course, it displays all programs. When we are interested in a particular program, check whether the name of the program is the same as we are interested.
Reviewing entries in the register in this branch, you can find lots of other interesting information about installed programs. These include, for example:
- version number,
- Date of installation,
- installation source,
- path to run the installer, to modify the features installed,
- path to run the installer, you uninstall an installed application,
- name of manufacturer of the application,
- the estimated size of the application,
- information, installed application or can be repaired or modified by the installer.
In addition to the above items, there are many other information, which can be found there. Just keep in mind, that not all information is available for all programs. So best to check before trying to use them, whether the application, we are interested in using them.
Taki ładny kod LINQu do generowania listy aplikacji a taki “brzydki” kod do ich wypisania. Nie ładniej tak:
Array.ForEach(query.Where(x => x.Application != null).Select(x => x).ToArray(),
x => Console.WriteLine(string.Format(“{0} -- {1}”, x.Application, x.InstallLocation)));
Pozdrawiam,
Paweł