0

可能重复:
如何检查 dll 是否已注册?

我需要查看本地机器是否安装了 SlimDX.dll。如何获取安装 dll 的列表?dll 的路径是 -> C:\Windows\Microsoft.NET\assembly\GAC_32

string  path="";
rk = Registry.LocalMachine.OpenSubKey("");
 string[] keys = rk.GetSubKeyNames();
foreach (string keyName in keys)
 {
       RegistryKey subKey = rk.OpenSubKey(keyName);
 }

这是正确的方法吗?

4

2 回答 2

1

你可以看看这里:

"以编程方式检查程序集是否使用 C# 在 GAC 中加载"

如果链接变坏:

public static bool AssemblyExist(string assemblyname, out string response)
{
    try
    {
        response = QueryAssemblyInfo(assemblyname);
        return true;
    }
    catch (System.IO.FileNotFoundException e)
    {
        response = e.Message;
        return false;
    }
}

// If assemblyName is not fully qualified, a random matching may be 
public static String QueryAssemblyInfo(string assemblyName)
{
    var assembyInfo = new AssemblyInfo {cchBuf = 512};
    assembyInfo.currentAssemblyPath = new String('', assembyInfo.cchBuf);

    IAssemblyCache assemblyCache;

    // Get IAssemblyCache pointer
    var hr = GacApi.CreateAssemblyCache(out assemblyCache, 0);
    if (hr == IntPtr.Zero)
    {
        hr = assemblyCache.QueryAssemblyInfo(1, assemblyName, ref assembyInfo);
        if (hr != IntPtr.Zero)
        {
            Marshal.ThrowExceptionForHR(hr.ToInt32());
        }
    }
    else
    {
        Marshal.ThrowExceptionForHR(hr.ToInt32());
    }
    return assembyInfo.currentAssemblyPath;
}
于 2012-05-30T09:22:34.453 回答
1

可以通过以下代码获取 GAC 中可用的 dll 列表。有关更多详细信息,请访问http://www.developerfusion.com/thread/42116/getting-list-of-assemblies-in-gac/

string strGacDir = @"C:\Windows\Microsoft.NET\assembly\GAC_32";
string[] strDirs1 = System.IO.Directory.GetDirectories(strGacDir);
string[] strDirs2;

string[] strFiles;

foreach (string strDir1 in strDirs1)
{
    strDirs2 = System.IO.Directory.GetDirectories(strDir1);

    foreach (string strDir2 in strDirs2)
    {
        strFiles = System.IO.Directory.GetFiles(strDir2, "SlimDX.dll");
        foreach (string strFile in strFiles)
        {
            return true;
        }
    }
}     
于 2012-05-31T03:49:10.697 回答