user1375535
user1375535

Reputation:

find application path in Registry

I need list of installed application on the computer and their path directory, and I find this:

     //Registry path which has information of all the softwares installed on machine
    string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
    {
        foreach (string skName in rk.GetSubKeyNames())
        {
            using (RegistryKey sk = rk.OpenSubKey(skName))
            {
                // we have many attributes other than these which are useful.
                Console.WriteLine(sk.GetValue("DisplayName") + 
            "  " + sk.GetValue("DisplayVersion"));
            }

        }
    }

How I get the path? I tried sk.GetValue("DisplayPath")but it not work.

Thanks!

Upvotes: 4

Views: 5429

Answers (2)

m-schwob
m-schwob

Reputation: 89

For get the path I find that: GetValue("InstallLocation")

It's work but for so many value it get 'null' or "".

Upvotes: 1

YoryeNathan
YoryeNathan

Reputation: 14502

Each software will have a different name for InstallLocation, if it will be there at all.

The one thing that will always be is UninstallString, which returns the path of the uninstaller (exe), which you can strip the directory from.

However, you should know that you will not get all installed programs there, if you go by HKEY_CURRENT_USER.

You should go via HKEY_LOCAL_MACHINE.

So, the code you are seeking is:

string uninstallExePath = sk.GetValue("UninstallString");
DirectoryInfo directory = new FileInfo(uninstallExePath).Directory;

string directoryPath = directory.FullName;

Upvotes: 3

Related Questions