LoginSignup
6
8

More than 5 years have passed since last update.

ClickOnce アプリケーションがインストールされているか確認する方法

Last updated at Posted at 2015-07-10

ClickOnce アプリケーションがインストールされているか確認するための API が提供されていないため、レジストリにアンインストール情報があるかどうかで判定する。

レジストリキー
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
の下に、 DisplayName が調べたいアプリケーション名と一致するキーがあるかどうかで判定する。

C#
    RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");

    if (regKey == null)
    {
        // レジストリキーがなければ、インストールされていない。
        return;
    }

    string[] subKeyNames = regKey.GetSubKeyNames();
    regKey.Close();

    foreach (string subKeyName in subKeyNames)
    {
        RegistryKey subKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\" + subKeyName);
        string displayName = (string)subKey.GetValue("DisplayName", string.Empty);
        subKey.Close();

        if (displayName == "調べたいアプリケーション名")
        {
            // 調べたいアプリケーション名と DisplayName が一致すれば、インストールされている。
            return;
        }
    }

    // 調べたいアプリケーション名と一致する DisplayName のキーが見つからなければ、インストールされていない。
    return;
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8