0

Possible Duplicate:
How to check if a dll is registered?

I need to find whether local machine had install SlimDX.dll. How can i get the list of install dlls? path of the dll is -> 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);
 }

is this the correct way to do it?

Community
  • 1
  • 1
DevT
  • 4,843
  • 16
  • 59
  • 92
  • possible duplicate : http://stackoverflow.com/questions/689072/how-to-check-if-a-dll-is-registered or http://stackoverflow.com/questions/377551/physicalinstalled-path-of-dll-installed-to-the-gac – Raphaël Althaus May 30 '12 at 08:20
  • According to that it gives assembly that contains the code that is currently executing. but i need particular dll. – DevT May 30 '12 at 08:46
  • by using registry we can not do it. :) – DevT May 31 '12 at 05:27

2 Answers2

1

you could have a look here:

"Programmatically check if an assembly is loaded in GAC with C#"

if the link turns bad:

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;
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
laar rommel
  • 33
  • 1
  • 4
1

can get the list of available dll in GAC through following code. for more details visit 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;
        }
    }
}     
DevT
  • 4,843
  • 16
  • 59
  • 92