1

I want to check for the installation of a third party application during the installation of my .NET Windows Form application or when it is opened. My Windows Form application doesn't require the third party application to run but it does need it for a feature to work. For example, My Windows Form application opens up the third party application such as a mail program.

I don't know if Click Once is the right strategy for this? I would need it to check for the prerequisite during installation and if it's not there notify the user to install it first. If Click Once isn't the right strategy for this is there another way? Maybe I need to install my Windows Form application first then when it is opened it checks for the third party application? The problem with that is, the installation path could vary from machine to machine. I'm not really sure how to go about this.

This link explains how to include prerequisites in Click Once but that's not what I want to do.

Another link that talks about including the prerequisites but not just detecting them.

Community
  • 1
  • 1
Heinrich
  • 1,711
  • 5
  • 28
  • 61

1 Answers1

2

One possible solution is to check registry with this method that returns bool value indicating whether the registry record with application name exists :

public static bool IsApplictionInstalled(string p_name)
{
    string displayName;
    RegistryKey key;

    // search in: CurrentUser
    key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
    foreach (String keyName in key.GetSubKeyNames())
    {
        RegistryKey subkey = key.OpenSubKey(keyName);
        displayName = subkey.GetValue("DisplayName") as string;
        if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
        {
            return true;
        }
    }

    // search in: LocalMachine_32
    key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
    foreach (String keyName in key.GetSubKeyNames())
    {
        RegistryKey subkey = key.OpenSubKey(keyName);
        displayName = subkey.GetValue("DisplayName") as string;
        if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
        {
            return true;
        }
    }

    // search in: LocalMachine_64
    key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
    foreach (String keyName in key.GetSubKeyNames())
    {
        RegistryKey subkey = key.OpenSubKey(keyName);
        displayName = subkey.GetValue("DisplayName") as string;
        if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
        {
            return true;
        }
    }

    // NOT FOUND
    return false;
}
Fabjan
  • 13,506
  • 4
  • 25
  • 52
  • I will try this, how do I know the correct application name for `p_name`? Do I use the name of the `exe`? – Heinrich Oct 10 '15 at 17:18
  • 1
    Well, first i'd find the program manually in one of three locations you can find in code. For example : `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\YourProgramName\DispayName` and check what value is written there, then use this value with this method programatically. – Fabjan Oct 10 '15 at 17:40