Nemo
Nemo

Reputation: 4741

How to check with C# where a program is installed

I need to check where a program is installed by program name (name that appears in Add or Remove Programs). What is the best way to that so that it'd work fine for all languages.

Upvotes: 7

Views: 14611

Answers (3)

Leigh
Leigh

Reputation: 1533

To add to Oliver's answer I have wrapped up this check inside a static method.

public static bool IsProgramInstalled(string programDisplayName) {

    Console.WriteLine(string.Format("Checking install status of: {0}",  programDisplayName));
    foreach (var item in Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").GetSubKeyNames()) {

        object programName = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("DisplayName");

        Console.WriteLine(programName);

        if (string.Equals(programName, programDisplayName)) {
            Console.WriteLine("Install status: INSTALLED");
            return true;
        }
    }
    Console.WriteLine("Install status: NOT INSTALLED");
    return false;
}

Upvotes: 10

Oliver
Oliver

Reputation: 45119

Take a look into the registry at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Just iterate over all subkeys and take a look into the values DisplayName and InstallLocation. Here you'll find the infos you want and much more ;-)

Upvotes: 13

Related Questions