0

我正在创建一个基本软件,我想在本地机器上检查特定的软件,然后选中一个框以指示该软件在机器上。我经历了多个线程,发现了一段简短而甜蜜的代码。但是,我无法将返回值或 true 或 false 与我的复选框联系起来。有人能告诉我我是否正确使用了这段代码吗?本质上,我想在几个不同的参数下检查卸载中可用的项目列表(以覆盖我的 32 位和 64 位操作系统的基础),在这种情况下,我正在搜索一个名为 Symantec Encryption 的软件。

 public static bool IsApplictionInstalled(string PGP)
    {
        string keyName;

        // search in: CurrentUser
        keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        if (ExistsInSubKey(Registry.CurrentUser, keyName, "Symantec Encryption", PGP) == true)
        {
            return true;
        }

        // search in: LocalMachine_32
        keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        if (ExistsInSubKey(Registry.LocalMachine, keyName, "Symantec Encryption", PGP) == true)
        {
            return true;
        }

        // search in: LocalMachine_64
        keyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
        if (ExistsInSubKey(Registry.LocalMachine, keyName, "Symantec Encryption", PGP) == true)
        {
            return true;
        }

        return false;
    }


    public static bool ExistsInSubKey(RegistryKey p_root, string p_subKeyName, string p_attributeName, string PGP)
    {
        RegistryKey subkey;
        string displayName;

        using (RegistryKey key = p_root.OpenSubKey(p_subKeyName))
        {
            if (key != null)
            {
                foreach (string kn in key.GetSubKeyNames())
                {
                    using (subkey = key.OpenSubKey(kn))
                    {
                        displayName = subkey.GetValue(p_attributeName) as string;
                        if (PGP.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                        {
                            return true;

                        }
                    }
                }
            }
        }
        return false;
    }

    public void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (PGP == true)
        {
            checkBox1.Checked = true;
        }
    }
    // ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------END------------------------------------------------------------------------------------------------------
4

1 回答 1

-1

你甚至没有接近。您需要调用IsApplicationInstalled,并使用该函数的返回值。

public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    checkBox1.Checked = IsApplicationInstalled(PGP);
}
于 2015-05-18T19:22:06.860 回答