/// <summary> /// IsSnapinInstalled method implementation /// </summary> private static bool IsSnapinInstalled(Session session, string dllFilename) { string xx = @"Neos.IdentityServer.Console.ADFSSnapIn, Neos.IdentityServer.Console, Version=3.0.0.0, Culture=neutral, PublicKeyToken=175aa5ee756d2aa2"; if (!File.Exists(dllFilename)) { return(false); } else { RegistryKey rkey64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); try { RegistryKey key = rkey64.OpenSubKey(@"Software\Microsoft\MMC\Snapins\FX:{9627F1F3-A6D2-4cf8-90A2-10F85A7A4EE7}", RegistryKeyPermissionCheck.ReadSubTree); try { object o = key.GetValue("Type"); if (o != null) { Assembly assembly = Assembly.LoadFile(dllFilename); foreach (Type type in assembly.GetTypes()) { if (type.IsDefined(typeof(SnapInSettingsAttribute))) { SnapInSettingsAttribute attrib = (SnapInSettingsAttribute)type.GetCustomAttribute(typeof(SnapInSettingsAttribute), false); if (attrib != null) { return(type.AssemblyQualifiedName.ToLower().Equals(xx.ToLower())); } } } } } catch { return(false); } finally { key.Close(); } } catch { return(false); } finally { rkey64.Close(); } } return(false); }
/// <summary> /// GetSettingsAttibutes method implementation /// </summary> private List <SnapinAttributeSettings> GetSettingsAttibutes() { List <SnapinAttributeSettings> lst = new List <SnapinAttributeSettings>(); Assembly assembly = Assembly.GetExecutingAssembly(); foreach (Type type in assembly.GetTypes()) { SnapinAttributeSettings att = new SnapinAttributeSettings(); if (type.IsDefined(typeof(SnapInSettingsAttribute))) { SnapInSettingsAttribute attribs = (SnapInSettingsAttribute)type.GetCustomAttribute(typeof(SnapInSettingsAttribute), false); if (attribs != null) { att.Settings = attribs; att.SnapinClass = type; att.AssemblyQualifiedName = type.AssemblyQualifiedName; att.FullName = type.FullName; att.AssemblyName = type.Assembly.GetName().Name + ".dll"; att.CodeBase = new Uri(type.Assembly.CodeBase).LocalPath; att.IsSet = true; } } if (type.IsDefined(typeof(SnapInAboutAttribute))) { SnapInAboutAttribute attribs = (SnapInAboutAttribute)type.GetCustomAttribute(typeof(SnapInAboutAttribute), false); if (attribs != null) { att.About = attribs; att.ApplicationBaseRelative = attribs.ApplicationBaseRelative; att.DescriptionId = attribs.DescriptionId; att.DisplayNameId = attribs.DisplayNameId; att.FolderBitmapsColorMask = attribs.FolderBitmapsColorMask; att.IconId = attribs.IconId; att.LargeFolderBitmapId = attribs.LargeFolderBitmapId; att.SmallFolderBitmapId = attribs.SmallFolderBitmapId; att.SmallFolderSelectedBitmapId = attribs.SmallFolderSelectedBitmapId; att.ProviderId = attribs.VendorId; att.VersionId = attribs.VersionId; } } if (att.IsSet) { lst.Add(att); } } return(lst); }