本文介绍了使用C#获取安装的软件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试获取已安装的应用程序密钥的列表:

I try to get a list of installed application keys:

RegistryKey RegKeyUninstallList = Registry.LocalMachine;
string strUninstallList = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string[] test = RegKeyUninstallList.OpenSubKey(strUninstallList).GetSubKeyNames();

我只能从以下位置获得钥匙:

I get only the Keys from:

但我还需要以下密钥:

我的程序应该能够在64Bit32Bit机器上运行.

My program should be able to run on a 64Bit and on a 32Bit machine.

好的,我已经尝试过检查应用程序是否已安装在注册表中以及来自tHiNk_OuT_oF_bOx的解决方案.

edit: Ok I have tried Check if application is installed in registry and the solution from tHiNk_OuT_oF_bOx.

但没有任何方法可以解决问题!

But nothing has solved the Problem!

问题是我得到了与test和test2完全相同的列表:

The problem is i get exactly the same list for test and test2:

RegistryKey RegKeyUninstallList = Registry.LocalMachine;
string strUninstallList = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
string strUninstallList2 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
string[] test = RegKeyUninstallList.OpenSubKey(strUninstallList).GetSubKeyNames();
string[] test2 = RegKeyUninstallList.OpenSubKey(strUninstallList2).GetSubKeyNames();

推荐答案

来源: http://social.msdn.microsoft.com/Forums/en-US/94c2f14d-c45e-4b55-9ba0-eb091bac1035/c-get-installed -程序

解决方案是在注册表中搜索3个位置:

The solution is to search for 3 places in registry:

  1. SOFTWARE \ Microsoft \ Windows \ CurrentVersion \在CurrentUser中卸载
  2. SOFTWARE \ Microsoft \ Windows \ CurrentVersion \在LocalMachine中卸载
  3. SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \在LocalMachine中卸载

下面的代码适合您的需求.

the code below suits you needs.

public static bool IsApplicationInstalled(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;
}

这篇关于使用C#获取安装的软件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:45