public static bool IsAssemblyExist(string name, string version) { var assemblyEnumerator = new AssemblyCacheEnumerator(); // Get the first assembly. var assemblyName = assemblyEnumerator.GetNextAssembly(); // Start to loop through the assemblies. while (assemblyName != null) { // The 'assemblyName' object is a COM interface, if we create an // AssemblyDescription from it, we will have access to more information. var assemblyDescription = new AssemblyDescription(assemblyName); if (assemblyDescription.Name.ToUpper().Trim() == name.ToUpper().Trim() && assemblyDescription.Version.Trim() == version.Trim()) { return true; } // Move to the next assembly. assemblyName = assemblyEnumerator.GetNextAssembly(); } return false; }
private static void GetSubKeys(RegistryKey SubKey, string b, string name) { foreach (string sub in SubKey.GetSubKeyNames()) { // MessageBox.Show(sub); // RegistryKey local = Registry.Users; RegistryKey local = SubKey.OpenSubKey(sub); if (local.GetValue(null) != null) { var v = local.GetValue(null); if (sub.ToString() == b) { AssemblyDescription asd = null; string c = local.Name.ToString(); //RegistryKey r = local.OpenSubKey(local.GetValue(null).ToString()); //if(v.ToString().EndsWith(".dll") == true) asd = new GACManagerApi.AssemblyDescription(v.ToString(), "", true); asd.Name = name; C.Add(asd); } } GetSubKeys(local, b, name); // By recalling itself it makes sure it get all the subkey names } }
public void LoadTypeLibraries(ArrayList asm) { InitializeListView(lv); A = new ArrayList(); foreach (object obs in asm) { if (obs == null) { continue; } GACManagerApi.AssemblyDescription ase = obs as GACManagerApi.AssemblyDescription; if (A.IndexOf(ase.Name) >= 0) { continue; } else { A.Add(ase.Name); } if (ase.ProcessorArchitecture != "" && ase.ProcessorArchitecture != null) { continue; } ListViewItem v = new ListViewItem(); v.Text = ""; lv.Columns[0].TextAlign = HorizontalAlignment.Center; v.SubItems.Add(ase.Name.ToString()); v.SubItems.Add(ase.Path); v.SubItems.Add(ase.ProcessorArchitecture); // v.SubItems.Add(ase.ReflectionProperties.ToString()); v.SubItems.Add(ase.Version); //v.SubItems.Add(ase.DisplayName.ToString()); lv.Items.Add(v); } }
public static ArrayList LoadFramework(DirectoryInfo d) { ArrayList L = new ArrayList(); string folder = d.FullName; FileInfo[] g = d.GetFiles(); foreach (FileInfo c in g) { if (c.Extension != ".dll") { continue; } AssemblyDescription desc = new AssemblyDescription(c.FullName, ""); L.Add(desc); } return(L); }
public static ArrayList GetExtensionFiles(DirectoryInfo d, bool subfolders = true) { ArrayList L = new ArrayList(); DirectoryInfo[] dd = new DirectoryInfo[] { d }; if (subfolders) { d.GetDirectories(); } foreach (DirectoryInfo s in dd) { DirectoryInfo[] c = s.GetDirectories(); if (c.Length <= 0) { continue; } DirectoryInfo cc = c[0]; FileInfo[] f = cc.GetFiles(); foreach (FileInfo g in f) { if (g.FullName.EndsWith(".dll") == false) { continue; } AssemblyDescription desc = new AssemblyDescription(g.FullName, ""); L.Add(desc); } } return(L); }
public static List<AssemblyDescription> GetAllGACAssembly() { var list = new List<AssemblyDescription>(); var assemblyEnumerator = new AssemblyCacheEnumerator(); // Get the first assembly. var assemblyName = assemblyEnumerator.GetNextAssembly(); // Start to loop through the assemblies. while (assemblyName != null) { // The 'assemblyName' object is a COM interface, if we create an // AssemblyDescription from it, we will have access to more information. var assemblyDescription = new AssemblyDescription(assemblyName); list.Add(assemblyDescription); // Move to the next assembly. assemblyName = assemblyEnumerator.GetNextAssembly(); } return list; }
public static List<DotnetLibrary> GetGACLibraries() { var gacList = new List<DotnetLibrary>(); try { var assemblyEnumerator = new AssemblyCacheEnumerator(); var assemblyName = assemblyEnumerator.GetNextAssembly(); while (assemblyName != null) { var assemblyDescription = new AssemblyDescription(assemblyName); string name = assemblyDescription.Name; bool probablyMicrosoftPackage = (name.StartsWith("Microsoft") || name.StartsWith("System")); if (!probablyMicrosoftPackage) { var gacLib = new DotnetLibrary { Culture = assemblyDescription.Culture, ProcessorArchitecture = assemblyDescription.ProcessorArchitecture, Name = name, Version = assemblyDescription.Version, Filepath = assemblyDescription.Path, }; FileInfo fi = new FileInfo(gacLib.Filepath); if (fi.Exists) { gacLib.Filename = fi.Name; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gacLib.Filepath); bool isDllFile = fvi.FileVersion != null; bool isMicrosoftCopyright = fvi.LegalCopyright != null && fvi.LegalCopyright.Contains("Microsoft Corporation"); if (isDllFile && !isMicrosoftCopyright) { gacLib.FileDescription = fvi.FileDescription; gacLib.Version = fvi.FileVersion; gacLib.ProductName = fvi.ProductName; gacLib.ProductVersion = fvi.ProductVersion; gacLib.Copyright = fvi.LegalCopyright; gacLib.Language = fvi.Language; gacLib.SHA1Hash = GetFileSHA1(gacLib.Filepath); gacLib.Md5Hash = GetFileMD5(gacLib.Filepath); gacList.Add(gacLib); } } } assemblyName = assemblyEnumerator.GetNextAssembly(); } } catch(Exception ex) { Trace.TraceWarning("Could not load DLL list from the GAC. Error: {0}", ex.ToString()); Console.Error.WriteLine("Could not load DLL list from the GAC."); return new List<DotnetLibrary>(); } return gacList; }